forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better error messages when the jest environment is used after teardow…
…n by async code (jestjs#7756)
- Loading branch information
1 parent
bfaa70b
commit 48e37b9
Showing
6 changed files
with
91 additions
and
21 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
13 changes: 13 additions & 0 deletions
13
e2e/__tests__/__snapshots__/environmentAfterTeardown.test.js.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,13 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`prints useful error for environment methods after test is done 1`] = ` | ||
ReferenceError: You are trying to access a property or method of the Jest environment after it has been torn down. | ||
9 | test('access environment methods after done', () => { | ||
10 | setTimeout(() => { | ||
> 11 | jest.clearAllTimers(); | ||
| ^ | ||
12 | }, 0); | ||
13 | }); | ||
14 | | ||
`; |
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. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import runJest from '../runJest'; | ||
import {wrap} from 'jest-snapshot-serializer-raw'; | ||
|
||
test('prints useful error for environment methods after test is done', () => { | ||
const {stderr} = runJest('environment-after-teardown'); | ||
const interestingLines = stderr | ||
.split('\n') | ||
.slice(9, 18) | ||
.join('\n'); | ||
|
||
expect(wrap(interestingLines)).toMatchSnapshot(); | ||
expect(stderr.split('\n')[9]).toBe( | ||
'ReferenceError: You are trying to access a property or method of the Jest environment after it has been torn down.', | ||
); | ||
}); |
13 changes: 13 additions & 0 deletions
13
e2e/environment-after-teardown/__tests__/afterTeardown.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,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. | ||
*/ | ||
'use strict'; | ||
|
||
test('access environment methods after done', () => { | ||
setTimeout(() => { | ||
jest.clearAllTimers(); | ||
}, 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,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