Skip to content

Commit

Permalink
[Tests] add describeIf.only; ensure itIf.only gets a boolean.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Aug 7, 2018
1 parent b938f2b commit 460ade7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/enzyme-example-mocha/test/.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function copyProps(src, target) {
Object.defineProperties(target, props);
}

global.expect = expect;
global.expect = expect;
global.window = window;
global.document = window.document;
global.navigator = {
Expand Down
16 changes: 16 additions & 0 deletions packages/enzyme-test-suite/test/_helpers/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ export function describeIf(test, a, b) {
}
}

describeIf.only = (test, a, b) => {
if (typeof test !== 'boolean') {
throw new TypeError(`a boolean is required, you passed a ${typeof test}`);
}

if (test) {
describe.only(a, b);
} else {
describe.skip(a, b);
}
};

/**
* Simple wrapper around mocha it which allows a boolean to be passed in first which
* determines whether or not the test will be run
Expand All @@ -35,6 +47,10 @@ export function itIf(test, a, b) {
}

itIf.only = (test, a, b) => {
if (typeof test !== 'boolean') {
throw new TypeError(`a boolean is required, you passed a ${typeof test}`);
}

if (test) {
it.only(a, b);
} else {
Expand Down

0 comments on commit 460ade7

Please sign in to comment.