-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
feat: fail tests when multiple done() calls are made
#10624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+264
−22
Merged
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
4612898
fix: 'done' should not be called more than once
flozender b6507c8
fix import order
flozender 7939e21
Merge branch 'master' of https://github.com/facebook/jest into fail-done
flozender f4253ca
fix snapshot line number
flozender 1b2b07d
Update CHANGELOG.md
flozender 300ab59
replace `then` with `await`
flozender d507eb1
move seenDone check after environment teardown check
flozender f5e61d3
add `completed` to `seenDone` check
flozender e03d211
add reason to message
flozender 3dd1f5e
reset `seenDone` before each test and hook
flozender 9364669
reset `seenDone` before each test and hook
flozender ffacfef
Merge branch 'fail-done' of https://github.com/mlh-fellowship/jest in…
flozender 1b92362
Update packages/jest-circus/src/utils.ts
flozender 113264f
reuse error, update snapshot, and add `seenDone` resets
flozender 66d6092
update snapshot
flozender b3929c8
test multiple `done` inside a hook
flozender 92a09b2
skip on jasmine
flozender b661de8
add all hooks
flozender 50938cd
add all hooks
flozender ad7c69e
add all hooks
flozender 8f9fcd3
Merge branch 'master' into fail-done
SimenB 7cdb33a
Update utils.ts
SimenB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,19 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`\`done()\` should not be called more than once 1`] = ` | ||
| FAIL __tests__/index.test.js | ||
| ✕ \`done()\` should not be called more than once | ||
|
|
||
| ● \`done()\` should not be called more than once | ||
|
|
||
| Expected done to be called once, but it was called multiple times. | ||
|
|
||
| 7 | test('\`done()\` should not be called more than once', done => { | ||
| 8 | done(); | ||
| > 9 | done(); | ||
| | ^ | ||
| 10 | }); | ||
| 11 | | ||
|
|
||
| at Object.done (__tests__/index.test.js:9:3) | ||
| `; |
This file contains hidden or 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 hidden or 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,18 @@ | ||
| /** | ||
| * 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 wrap from 'jest-snapshot-serializer-raw'; | ||
| import {skipSuiteOnJasmine} from '@jest/test-utils'; | ||
| import {extractSummary} from '../Utils'; | ||
| import runJest from '../runJest'; | ||
|
|
||
| skipSuiteOnJasmine(); | ||
| test('`done()` should not be called more than once', () => { | ||
| const {exitCode, stderr} = runJest('call-done-twice'); | ||
| const {rest} = extractSummary(stderr); | ||
| expect(wrap(rest)).toMatchSnapshot(); | ||
| expect(exitCode).toBe(1); | ||
| }); |
This file contains hidden or 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,13 @@ | ||
| /** | ||
| * 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 runJest from '../runJest'; | ||
|
|
||
| test('`done()` works properly in hooks', () => { | ||
| const {exitCode} = runJest('done-in-hooks'); | ||
| expect(exitCode).toEqual(0); | ||
| }); |
This file contains hidden or 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,21 @@ | ||
| /** | ||
| * 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('`done()` called more than once', () => { | ||
| it('should fail', done => { | ||
| done(); | ||
| done(); | ||
| }); | ||
|
|
||
| it('should fail inside a promise', done => { | ||
| Promise.resolve() | ||
| .then(() => { | ||
| done(); | ||
| done(); | ||
| }) | ||
| .catch(err => err); | ||
| }); | ||
flozender marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
This file contains hidden or 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 hidden or 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,16 @@ | ||
| /** | ||
| * 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('`done()` should work with hooks', done => { | ||
| beforeEach(done => done()); | ||
| it('foo', () => { | ||
| expect('foo').toMatch('foo'); | ||
| }); | ||
| it('bar', () => { | ||
| expect('bar').toMatch('bar'); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.