From a9700b789548cd9645b509d369161ee7b9d936f9 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 6 Oct 2018 17:02:33 +0200 Subject: [PATCH] fix circus --- CHANGELOG.md | 3 +- .../__snapshots__/globals.test.js.snap | 1 - packages/jest-circus/src/index.js | 41 +++++++++++++------ 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48a7e715e31d..461537e90231 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/e2e/__tests__/__snapshots__/globals.test.js.snap b/e2e/__tests__/__snapshots__/globals.test.js.snap index e2718a94c079..5c9e0c987dc8 100644 --- a/e2e/__tests__/__snapshots__/globals.test.js.snap +++ b/e2e/__tests__/__snapshots__/globals.test.js.snap @@ -30,7 +30,6 @@ exports[`cannot have describe with no implementation 1`] = ` | ^ 3 | - at packages/jest-jasmine2/build/jasmine/Env.js:<>:<> at __tests__/only-constructs.test.js:<>:<> " diff --git a/packages/jest-circus/src/index.js b/packages/jest-circus/src/index.js index 868e9f9c542b..157af8bc48b9 100644 --- a/packages/jest-circus/src/index.js +++ b/packages/jest-circus/src/index.js @@ -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',