Skip to content

Commit

Permalink
adds .skip and .only functionality to describeWithDOM
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate Piche committed Jan 19, 2016
1 parent 46f4d36 commit 803b114
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/ReactWrapper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
mount,
render,
ReactWrapper,
describeWithDOM,
} from '../';
import { describeWithDOM } from '../describeWithDOM';
import { describeIf } from './_helpers';
import { REACT013 } from '../version';

Expand Down
4 changes: 3 additions & 1 deletion src/__tests__/Utils-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import {
mapNativeEventNames,
} from '../Utils';
import {
describeWithDOM,
mount,
} from '../';
import {
describeWithDOM,
} from '../describeWithDOM';

describe('Utils', () => {

Expand Down
21 changes: 21 additions & 0 deletions src/__tests__/describeWithDOM-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import { expect } from 'chai';
import { mount } from '../';
import { describeWithDOM } from '../describeWithDOM';

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 called
expect(true).to.equal(false);
});
});

describeWithDOM('will still call describeWithDOM 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;
20 changes: 0 additions & 20 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,8 @@ 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

0 comments on commit 803b114

Please sign in to comment.