Skip to content

Commit 8a7301d

Browse files
authored
Fail on console.error in tests with failOnConsole (github#25600)
* Install jest-fail-on-console * Setup and use failOnConsole * Add intentional 'unique key' error * Revert "Add intentional 'unique key' error" This reverts commit 5f75f069d80df36ce632421ae7ad26e98ac17ad3. * Comment about why use this package
1 parent 156ec4b commit 8a7301d

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = {
2929
},
3030
reporters,
3131
modulePathIgnorePatterns: ['assets/'],
32-
setupFilesAfterEnv: ['@alex_neo/jest-expect-message'],
32+
setupFilesAfterEnv: ['./jest.setup.js', '@alex_neo/jest-expect-message'],
3333
...(isBrowser ? {} : { testEnvironment: 'node' }),
3434
testPathIgnorePatterns: [
3535
'node_modules/',

jest.setup.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import failOnConsole from 'jest-fail-on-console'
2+
3+
// Jest tests don't fail in some cases where we would see an error in DevTools
4+
// Console when running locally and we would also see the error in the test
5+
// output. This includes the React `Each child in a list should have a unique
6+
// "key" prop` error example.
7+
//
8+
// To catch this and fail tests in cases like this, we use `jest-fail-on-console`
9+
// to fail on calls to `console.error()`.
10+
failOnConsole({
11+
shouldFailOnWarn: false,
12+
})

package-lock.json

+47
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
"japanese-characters": "^1.1.0",
141141
"javascript-stringify": "^2.1.0",
142142
"jest": "^27.4.7",
143+
"jest-fail-on-console": "^2.2.3",
143144
"jest-github-actions-reporter": "^1.0.3",
144145
"jest-slow-test-reporter": "^1.0.0",
145146
"linkinator": "^3.0.3",

0 commit comments

Comments
 (0)