-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jest-circus: throw if a test / hook is defined asynchronously (#8096)
- Loading branch information
Showing
9 changed files
with
134 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
e2e/__tests__/__snapshots__/circusDeclarationErrors.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`defining tests and hooks asynchronously throws 1`] = ` | ||
FAIL __tests__/asyncDefinition.test.js | ||
● Test suite failed to run | ||
Cannot add a test after tests have started running. Tests must be defined synchronously. | ||
10 | | ||
11 | Promise.resolve().then(() => { | ||
> 12 | test('async definition inside describe', () => {}); | ||
| ^ | ||
13 | afterAll(() => {}); | ||
14 | }); | ||
15 | }); | ||
at test (__tests__/asyncDefinition.test.js:12:5) | ||
● Test suite failed to run | ||
Cannot add a hook after tests have started running. Hooks must be defined synchronously. | ||
11 | Promise.resolve().then(() => { | ||
12 | test('async definition inside describe', () => {}); | ||
> 13 | afterAll(() => {}); | ||
| ^ | ||
14 | }); | ||
15 | }); | ||
16 | | ||
at afterAll (__tests__/asyncDefinition.test.js:13:5) | ||
● Test suite failed to run | ||
Cannot add a test after tests have started running. Tests must be defined synchronously. | ||
16 | | ||
17 | Promise.resolve().then(() => { | ||
> 18 | test('async definition outside describe', () => {}); | ||
| ^ | ||
19 | afterAll(() => {}); | ||
20 | }); | ||
21 | | ||
at test (__tests__/asyncDefinition.test.js:18:3) | ||
● Test suite failed to run | ||
Cannot add a hook after tests have started running. Hooks must be defined synchronously. | ||
17 | Promise.resolve().then(() => { | ||
18 | test('async definition outside describe', () => {}); | ||
> 19 | afterAll(() => {}); | ||
| ^ | ||
20 | }); | ||
21 | | ||
at afterAll (__tests__/asyncDefinition.test.js:19:3) | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {skipSuiteOnJasmine} from '@jest/test-utils'; | ||
import {wrap} from 'jest-snapshot-serializer-raw'; | ||
import {extractSummary} from '../Utils'; | ||
import runJest from '../runJest'; | ||
|
||
skipSuiteOnJasmine(); | ||
|
||
it('defining tests and hooks asynchronously throws', () => { | ||
const result = runJest('circus-declaration-errors', [ | ||
'asyncDefinition.test.js', | ||
]); | ||
|
||
expect(result.exitCode).toBe(1); | ||
|
||
const {rest} = extractSummary(result.stderr); | ||
expect(wrap(rest)).toMatchSnapshot(); | ||
}); |
20 changes: 20 additions & 0 deletions
20
e2e/circus-declaration-errors/__tests__/asyncDefinition.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
describe('describe', () => { | ||
test('correct test def', () => {}); | ||
|
||
Promise.resolve().then(() => { | ||
test('async definition inside describe', () => {}); | ||
afterAll(() => {}); | ||
}); | ||
}); | ||
|
||
Promise.resolve().then(() => { | ||
test('async definition outside describe', () => {}); | ||
afterAll(() => {}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"jest": { | ||
"testEnvironment": "node" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters