Skip to content

Commit

Permalink
Fail on console.error in tests with failOnConsole (github#25600)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rsese authored Feb 25, 2022
1 parent 156ec4b commit 8a7301d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = {
},
reporters,
modulePathIgnorePatterns: ['assets/'],
setupFilesAfterEnv: ['@alex_neo/jest-expect-message'],
setupFilesAfterEnv: ['./jest.setup.js', '@alex_neo/jest-expect-message'],
...(isBrowser ? {} : { testEnvironment: 'node' }),
testPathIgnorePatterns: [
'node_modules/',
Expand Down
12 changes: 12 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import failOnConsole from 'jest-fail-on-console'

// Jest tests don't fail in some cases where we would see an error in DevTools
// Console when running locally and we would also see the error in the test
// output. This includes the React `Each child in a list should have a unique
// "key" prop` error example.
//
// To catch this and fail tests in cases like this, we use `jest-fail-on-console`
// to fail on calls to `console.error()`.
failOnConsole({
shouldFailOnWarn: false,
})
47 changes: 47 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
"japanese-characters": "^1.1.0",
"javascript-stringify": "^2.1.0",
"jest": "^27.4.7",
"jest-fail-on-console": "^2.2.3",
"jest-github-actions-reporter": "^1.0.3",
"jest-slow-test-reporter": "^1.0.0",
"linkinator": "^3.0.3",
Expand Down

0 comments on commit 8a7301d

Please sign in to comment.