Skip to content

Commit

Permalink
Merge pull request #126 from nfpiche/describeWithDOM-enhancement
Browse files Browse the repository at this point in the history
describeWithDOM enhancement
  • Loading branch information
lelandrichardson committed Jan 21, 2016
2 parents cdc7aaa + 975160a commit d9606b7
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 21 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"check": "npm run lint && npm run test:all",
"build": "babel src --out-dir build",
"test:watch": "mocha --compilers js:babel/register --recursive src/**/__tests__/*.js --watch",
"test:all": "npm run react:13 && npm test && npm run react:14 && npm test",
"test:describeWithDOMOnly": "mocha --compilers js:babel/register --recursive src/**/__tests__/describeWithDOM/describeWithDOMOnly-spec.js",
"test:describeWithDOMSkip": "mocha --compilers js:babel/register --recursive src/**/__tests__/describeWithDOM/describeWithDOMSkip-spec.js",
"test:all": "npm run react:13 && npm test && npm run test:describeWithDOMOnly && npm run test:describeWithDOMSkip && npm run react:14 && npm test && npm run test:describeWithDOMOnly && npm run test:describeWithDOMSkip",
"react:clean": "rimraf node_modules/react node_modules/react-dom node_modules/react-addons-test-utils",
"react:13": "npm run react:clean && npm i [email protected]",
"react:14": "npm run react:clean && npm i [email protected] [email protected] [email protected]",
Expand Down
19 changes: 19 additions & 0 deletions src/__tests__/describeWithDOM/describeWithDOMOnly-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { expect } from 'chai';
import { describeWithDOM } from '../..';

describe('describeWithDOM', () => {
describe('.only()', () => {
describeWithDOM.only('will skip all tests not called with only', () => {
it('will run only this test', () => {
expect(true).to.equal(true);
});
});

describeWithDOM('will not call other tests', () => {
it('will not run this test', () => {
// purposefully failing test that won't be called
expect(true).to.equal(false);
});
});
});
});
19 changes: 19 additions & 0 deletions src/__tests__/describeWithDOM/describeWithDOMSkip-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { expect } from 'chai';
import { describeWithDOM } from '../..';

describe('describeWithDOM', () => {
describe('.skip()', () => {
describeWithDOM.skip('will skip tests called with skip', () => {
it('will not run this test', () => {
// purposefully failing test that won't be run
expect(true).to.equal(false);
});
});

describeWithDOM('will still call describeWithDOM tests without .skip', () => {
it('will run this test', () => {
expect(true).to.equal(true);
});
});
});
});
47 changes: 47 additions & 0 deletions src/describeWithDOM.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
let jsdom;

try {
require('jsdom'); // could throw
jsdom = require('mocha-jsdom');
} catch (e) {
// jsdom is not supported...
}

export function describeWithDOM(a, b) {
describe('(uses jsdom)', () => {
if (typeof jsdom === 'function') {
jsdom();
describe(a, b);
} else {
// if jsdom isn't available, skip every test in this describe context
describe.skip(a, b);
}
});
}

function only(a, b) {
describe('(uses jsdom)', () => {
if (typeof jsdom === 'function') {
jsdom();
describe.only(a, b);
} else {
// if jsdom isn't available, skip every test in this describe context
describe.skip(a, b);
}
});
}

function skip(a, b) {
describe('(uses jsdom)', () => {
if (typeof jsdom === 'function') {
jsdom();
describe.skip(a, b);
} else {
// if jsdom isn't available, skip every test in this describe context
describe.skip(a, b);
}
});
}

describeWithDOM.only = only;
describeWithDOM.skip = skip;
22 changes: 2 additions & 20 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,16 @@ import cheerio from 'cheerio';
import Sinon from 'sinon';
import ReactWrapper from './ReactWrapper';
import ShallowWrapper from './ShallowWrapper';
import { describeWithDOM } from './describeWithDOM';
import { onPrototype } from './Utils';
import { renderToStaticMarkup } from './react-compat';

/**
* @class Enzyme
*/

let jsdom;
try {
require('jsdom'); // could throw
jsdom = require('mocha-jsdom');
} catch (e) {
// jsdom is not supported...
}

export let sinon = Sinon.sandbox.create();

export function describeWithDOM(a, b) {
describe('(uses jsdom)', () => {
if (typeof jsdom === 'function') {
jsdom();
describe(a, b);
} else {
// if jsdom isn't available, skip every test in this describe context
describe.skip(a, b);
}
});
}

export function useSetStateHack() {
let cleanup = false;
before(() => {
Expand Down Expand Up @@ -106,3 +87,4 @@ export function render(node) {

export { ShallowWrapper as ShallowWrapper };
export { ReactWrapper as ReactWrapper };
export { describeWithDOM as describeWithDOM };

0 comments on commit d9606b7

Please sign in to comment.