-
-
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: fail tests when multiple
done()
calls are made (#10624)
- Loading branch information
Showing
13 changed files
with
264 additions
and
22 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,89 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`\`done()\` should not be called more than once 1`] = ` | ||
FAIL __tests__/index.test.js | ||
● \`done()\` called more than once › should fail | ||
Expected done to be called once, but it was called multiple times. | ||
8 | it('should fail', done => { | ||
9 | done(); | ||
> 10 | done(); | ||
| ^ | ||
11 | }); | ||
12 | | ||
13 | it('should fail inside a promise', done => { | ||
at Object.done (__tests__/index.test.js:10:5) | ||
● \`done()\` called more than once › should fail inside a promise | ||
Expected done to be called once, but it was called multiple times. | ||
15 | .then(() => { | ||
16 | done(); | ||
> 17 | done(); | ||
| ^ | ||
18 | }) | ||
19 | .catch(err => err); | ||
20 | }); | ||
at done (__tests__/index.test.js:17:9) | ||
● multiple \`done()\` inside beforeEach › should fail | ||
Expected done to be called once, but it was called multiple times. | ||
24 | beforeEach(done => { | ||
25 | done(); | ||
> 26 | done(); | ||
| ^ | ||
27 | }); | ||
28 | | ||
29 | it('should fail', () => { | ||
at Object.done (__tests__/index.test.js:26:5) | ||
● multiple \`done()\` inside afterEach › should fail | ||
Expected done to be called once, but it was called multiple times. | ||
35 | afterEach(done => { | ||
36 | done(); | ||
> 37 | done(); | ||
| ^ | ||
38 | }); | ||
39 | | ||
40 | it('should fail', () => { | ||
at Object.done (__tests__/index.test.js:37:5) | ||
● multiple \`done()\` inside beforeAll › should fail | ||
Expected done to be called once, but it was called multiple times. | ||
46 | beforeAll(done => { | ||
47 | done(); | ||
> 48 | done(); | ||
| ^ | ||
49 | }); | ||
50 | | ||
51 | it('should fail', () => { | ||
at done (__tests__/index.test.js:48:5) | ||
● Test suite failed to run | ||
Expected done to be called once, but it was called multiple times. | ||
57 | afterAll(done => { | ||
58 | done(); | ||
> 59 | done(); | ||
| ^ | ||
60 | }); | ||
61 | | ||
62 | it('should fail', () => { | ||
at done (__tests__/index.test.js:59:5) | ||
`; |
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,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 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,15 @@ | ||
/** | ||
* 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 runJest from '../runJest'; | ||
|
||
skipSuiteOnJasmine(); | ||
test('`done()` works properly in hooks', () => { | ||
const {exitCode} = runJest('done-in-hooks'); | ||
expect(exitCode).toEqual(0); | ||
}); |
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,65 @@ | ||
/** | ||
* 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); | ||
}); | ||
}); | ||
|
||
describe('multiple `done()` inside beforeEach', () => { | ||
beforeEach(done => { | ||
done(); | ||
done(); | ||
}); | ||
|
||
it('should fail', () => { | ||
expect('foo').toMatch('foo'); | ||
}); | ||
}); | ||
|
||
describe('multiple `done()` inside afterEach', () => { | ||
afterEach(done => { | ||
done(); | ||
done(); | ||
}); | ||
|
||
it('should fail', () => { | ||
expect('foo').toMatch('foo'); | ||
}); | ||
}); | ||
|
||
describe('multiple `done()` inside beforeAll', () => { | ||
beforeAll(done => { | ||
done(); | ||
done(); | ||
}); | ||
|
||
it('should fail', () => { | ||
expect('foo').toMatch('foo'); | ||
}); | ||
}); | ||
|
||
describe('multiple `done()` inside afterAll', () => { | ||
afterAll(done => { | ||
done(); | ||
done(); | ||
}); | ||
|
||
it('should fail', () => { | ||
expect('foo').toMatch('foo'); | ||
}); | ||
}); |
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
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 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
Oops, something went wrong.