-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jest-circus): Fail tests if a test takes a done callback and hav…
…e return values (#9129)
- Loading branch information
Showing
8 changed files
with
164 additions
and
24 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
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,53 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`errors when a test both returns a promise and takes a callback 1`] = ` | ||
FAIL __tests__/promise-and-callback.test.js | ||
✕ promise-returning test with callback | ||
✕ async test with callback | ||
✕ test done before return value | ||
● promise-returning test with callback | ||
Test functions cannot both take a 'done' callback and return something. Either use a 'done' callback, or return a promise. | ||
Returned value: Promise {} | ||
8 | 'use strict'; | ||
9 | | ||
> 10 | it('promise-returning test with callback', done => { | ||
| ^ | ||
11 | done(); | ||
12 | | ||
13 | return Promise.resolve(); | ||
at Object.it (__tests__/promise-and-callback.test.js:10:1) | ||
● async test with callback | ||
Test functions cannot both take a 'done' callback and return something. Either use a 'done' callback, or return a promise. | ||
Returned value: Promise {} | ||
14 | }); | ||
15 | | ||
> 16 | it('async test with callback', async done => { | ||
| ^ | ||
17 | done(); | ||
18 | }); | ||
19 | | ||
at Object.it (__tests__/promise-and-callback.test.js:16:1) | ||
● test done before return value | ||
Test functions cannot both take a 'done' callback and return something. Either use a 'done' callback, or return a promise. | ||
Returned value: "foobar" | ||
18 | }); | ||
19 | | ||
> 20 | it('test done before return value', done => { | ||
| ^ | ||
21 | done(); | ||
22 | | ||
23 | return 'foobar'; | ||
at Object.it (__tests__/promise-and-callback.test.js:20:1) | ||
`; |
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,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. | ||
*/ | ||
|
||
import {skipSuiteOnJasmine} from '@jest/test-utils'; | ||
import wrap from 'jest-snapshot-serializer-raw'; | ||
import runJest from '../runJest'; | ||
import {extractSummary} from '../Utils'; | ||
|
||
skipSuiteOnJasmine(); | ||
|
||
test('errors when a test both returns a promise and takes a callback', () => { | ||
const result = runJest('promise-and-callback'); | ||
|
||
const {rest} = extractSummary(result.stderr); | ||
expect(wrap(rest)).toMatchSnapshot(); | ||
expect(result.exitCode).toBe(1); | ||
}); |
24 changes: 24 additions & 0 deletions
24
e2e/promise-and-callback/__tests__/promise-and-callback.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,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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
it('promise-returning test with callback', done => { | ||
done(); | ||
|
||
return Promise.resolve(); | ||
}); | ||
|
||
it('async test with callback', async done => { | ||
done(); | ||
}); | ||
|
||
it('test done before return value', done => { | ||
done(); | ||
|
||
return 'foobar'; | ||
}); |
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