Skip to content

Commit

Permalink
fix circus
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Oct 6, 2018
1 parent ed8c10c commit a9700b7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
- `[jest-jasmine2`] Fix crash when test return Promise rejected with null ([#7049](https://github.com/facebook/jest/pull/7049))
- `[jest-runtime]` Check `_isMockFunction` is true rather than truthy on potential global mocks ([#7017](https://github.com/facebook/jest/pull/7017))
- `[jest-jasmine]` Show proper error message from async `assert` errors ([#6821](https://github.com/facebook/jest/pull/6821))
- `[jest-jasmine2]` Better error message when a describe block is empty ([#6372](https://github.com/facebook/jest/pull/6372))
- `[jest-jasmine]` Better error message when a describe block is empty ([#6372](https://github.com/facebook/jest/pull/6372))
- `[jest-circus]` Better error message when a describe block is empty ([#6372](https://github.com/facebook/jest/pull/6372))

### Chore & Maintenance

Expand Down
1 change: 0 additions & 1 deletion e2e/__tests__/__snapshots__/globals.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ exports[`cannot have describe with no implementation 1`] = `
| ^
3 |
at packages/jest-jasmine2/build/jasmine/Env.js:<<LINE>>:<<COLUMN>>
at __tests__/only-constructs.test.js:<<LINE>>:<<COLUMN>>
"
Expand Down
41 changes: 29 additions & 12 deletions packages/jest-circus/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,42 @@ import {dispatch} from './state';
type THook = (fn: HookFn, timeout?: number) => void;

const describe = (blockName: BlockName, blockFn: BlockFn) =>
_dispatchDescribe(blockFn, blockName);
_dispatchDescribe(
blockFn,
blockName,
new ErrorWithStack(undefined, describe),
);
describe.only = (blockName: BlockName, blockFn: BlockFn) =>
_dispatchDescribe(blockFn, blockName, 'only');
_dispatchDescribe(
blockFn,
blockName,
new ErrorWithStack(undefined, describe.only),
'only',
);
describe.skip = (blockName: BlockName, blockFn: BlockFn) =>
_dispatchDescribe(blockFn, blockName, 'skip');

const _dispatchDescribe = (blockFn, blockName, mode?: BlockMode) => {
_dispatchDescribe(
blockFn,
blockName,
new ErrorWithStack(undefined, describe.skip),
'skip',
);

const _dispatchDescribe = (
blockFn,
blockName,
asyncError,
mode?: BlockMode,
) => {
if (blockFn === undefined) {
throw new Error(
`Missing second argument supplied to 'describe'. It must be a callback function.`,
);
asyncError.message = `Missing second argument supplied to 'describe'. It must be a callback function.`;
throw asyncError;
}
if (typeof blockFn !== 'function') {
throw new Error(
`Invalid second argument supplied to 'describe', ${blockFn}. It must be a callback function.`,
);
asyncError.message = `Invalid second argument supplied to 'describe', ${blockFn}. It must be a callback function.`;
throw asyncError;
}
dispatch({
asyncError: new Error(),
asyncError,
blockName,
mode,
name: 'start_describe_definition',
Expand Down

0 comments on commit a9700b7

Please sign in to comment.