Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsdom #6

Merged
merged 1 commit into from
Sep 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/dom.js
Original file line number Diff line number Diff line change
@@ -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('<!doctype html><html><body></body></html>');
var win = doc.defaultView;

global.document = doc;
global.window = win;

propagateToGlobal(win);
6 changes: 6 additions & 0 deletions lib/legit-tests.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* globals global */
'use strict';

Object.defineProperty(exports, '__esModule', {
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion mocha.opts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
--require ./tests/setup
--full-trace
--compilers js:babel/register
--recursive ./tests/**/*.jsx
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"webpack-dev-server": "^1.10.1"
},
"dependencies": {
"jsdom": "^6.5.0",
"react": "^0.13.3"
}
}
5 changes: 0 additions & 5 deletions tests/setup.js → src/dom.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
/* globals global */

require("babel/register")({
stage: 0
});

function propagateToGlobal (window) {
for (let key in window) {
if (!window.hasOwnProperty(key)) continue
Expand Down
4 changes: 4 additions & 0 deletions src/legit-tests.js
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
6 changes: 2 additions & 4 deletions tests/find.jsx
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
7 changes: 2 additions & 5 deletions tests/setState.jsx
Original file line number Diff line number Diff line change
@@ -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(<TestComponent/>)
Test(<TestComponent />)
.use(SetState, {test: 'test'})
.use(Find, 'div')
.test(({helpers}) => {
Expand Down
6 changes: 2 additions & 4 deletions tests/simulate.jsx
Original file line number Diff line number Diff line change
@@ -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', () => {

Expand Down