From aea3f15297ba567fb55b0d3c7bea85d5334845d3 Mon Sep 17 00:00:00 2001 From: Zach Date: Tue, 15 Sep 2015 23:32:32 -0700 Subject: [PATCH] added jsdmon to the library to make it easier to use --- lib/dom.js | 21 +++++++++++++++++++++ lib/legit-tests.js | 6 ++++++ mocha.opts | 1 - package.json | 1 + tests/setup.js => src/dom.js | 5 ----- src/legit-tests.js | 4 ++++ tests/find.jsx | 6 ++---- tests/setState.jsx | 7 ++----- tests/simulate.jsx | 6 ++---- 9 files changed, 38 insertions(+), 19 deletions(-) create mode 100644 lib/dom.js rename tests/setup.js => src/dom.js (89%) diff --git a/lib/dom.js b/lib/dom.js new file mode 100644 index 0000000..846072a --- /dev/null +++ b/lib/dom.js @@ -0,0 +1,21 @@ +/* globals global */ +'use strict'; + +function propagateToGlobal(window) { + for (var key in window) { + if (!window.hasOwnProperty(key)) continue; + if (key in global) continue; + + global[key] = window[key]; + } +} + +var jsdom = require('jsdom'); + +var doc = jsdom.jsdom(''); +var win = doc.defaultView; + +global.document = doc; +global.window = win; + +propagateToGlobal(win); \ No newline at end of file diff --git a/lib/legit-tests.js b/lib/legit-tests.js index aff871e..8771abb 100644 --- a/lib/legit-tests.js +++ b/lib/legit-tests.js @@ -1,3 +1,4 @@ +/* globals global */ 'use strict'; Object.defineProperty(exports, '__esModule', { @@ -12,12 +13,17 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'd function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } +require('./dom'); + var _reactAddons = require('react/addons'); var _reactAddons2 = _interopRequireDefault(_reactAddons); var TestUtils = _reactAddons2['default'].addons.TestUtils; +global.React = _reactAddons2['default']; //expose React to tests so they can use jsx syntax when passing in components to the class +require('react/lib/ExecutionEnvironment').canUseDOM = true; + var Test = (function () { function Test(component) { _classCallCheck(this, Test); diff --git a/mocha.opts b/mocha.opts index 8c60032..1b8420f 100644 --- a/mocha.opts +++ b/mocha.opts @@ -1,4 +1,3 @@ ---require ./tests/setup --full-trace --compilers js:babel/register --recursive ./tests/**/*.jsx diff --git a/package.json b/package.json index 6eb7b9d..a6d3bc3 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "webpack-dev-server": "^1.10.1" }, "dependencies": { + "jsdom": "^6.5.0", "react": "^0.13.3" } } diff --git a/tests/setup.js b/src/dom.js similarity index 89% rename from tests/setup.js rename to src/dom.js index a7eae1d..6d6cfd5 100644 --- a/tests/setup.js +++ b/src/dom.js @@ -1,9 +1,4 @@ /* globals global */ - -require("babel/register")({ - stage: 0 -}); - function propagateToGlobal (window) { for (let key in window) { if (!window.hasOwnProperty(key)) continue diff --git a/src/legit-tests.js b/src/legit-tests.js index 392fe4e..e17f102 100644 --- a/src/legit-tests.js +++ b/src/legit-tests.js @@ -1,5 +1,9 @@ +/* globals global */ +import './dom' import React from 'react/addons'; let { TestUtils } = React.addons +global.React = React //expose React to tests so they can use jsx syntax when passing in components to the class +require('react/lib/ExecutionEnvironment').canUseDOM = true class Test { diff --git a/tests/find.jsx b/tests/find.jsx index eb24836..fdac0ed 100644 --- a/tests/find.jsx +++ b/tests/find.jsx @@ -1,12 +1,10 @@ -import React from 'react' +import Test from '../src/legit-tests' +import {Find} from '../src/middleware' import { expect } from 'chai'; import TestComponent from './component' import TinyComponent from './tiny-component' -import Test from '../src/legit-tests' -import {Find} from '../src/middleware' - describe('Find middleware', () => { it('should find div', () => { diff --git a/tests/setState.jsx b/tests/setState.jsx index 4193715..f758999 100644 --- a/tests/setState.jsx +++ b/tests/setState.jsx @@ -1,16 +1,13 @@ -import React from 'react' +import Test from '../src/legit-tests' import { expect } from 'chai'; - import TestComponent from './component' - -import Test from '../src/legit-tests' import {SetState, Find} from '../src/middleware' describe('setState middleware', () => { it('should change state', () => { - Test() + Test() .use(SetState, {test: 'test'}) .use(Find, 'div') .test(({helpers}) => { diff --git a/tests/simulate.jsx b/tests/simulate.jsx index 9589fcd..962bbac 100644 --- a/tests/simulate.jsx +++ b/tests/simulate.jsx @@ -1,11 +1,9 @@ -import React from 'react' +import Test from '../src/legit-tests' +import {Find, Simulate} from '../src/middleware' import { expect } from 'chai'; import sinon from 'sinon'; - import TestComponent from './component' -import Test from '../src/legit-tests' -import {Find, Simulate} from '../src/middleware' describe('simulate middleware', () => {