Make a passing `.toThrow()` not dump to `console.error`
See original GitHub issueDo you want to request a feature or report a bug?
Feature
What is the current behavior?
Writing a test for an exception still dumps that exception to the output, which is very confusing: It took me a while to realize that buried after screen and screens of red stack traces, my tests were showing as PASS…
I don’t want to use --silent
during development, as I’d use the ability to quickly console.log
the shape of objects I’m trying to expect, etc…
As a work-around, I’m creating a spy on console.error
, but that of course also swallows and exceptions that I’m not yet testing for:
beforeAll(() => {
jest.spyOn(console, 'error').mockImplementation(() => undefined);
});
afterAll(() => {
console.error.mockRestore();
});
What is the expected behavior?
It would be great if exceptions happening inside .toThrow
would not get dumped to console IF they PASS the assertion. (I guess that would take some kind of buffering of the output?)
Please provide your exact Jest configuration
const path = require('path');
const isCI = process.argv.includes('--ci');
module.exports = {
rootDir: '../packages',
testMatch: ['**/__tests__/*.{js,jsx}', '**/*.{spec,test}?(s).{js,jsx}'],
collectCoverage: isCI,
collectCoverageFrom: [
'**/src/**?(/)*.{js,jsx}',
// ignore:
'!**/__stories__/**',
'!**/*.stories.{js,jsx}',
],
coverageDirectory: path.resolve(__dirname, '..', 'coverage'),
coverageThreshold: isCI
? {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 0,
},
}
: undefined,
};
Run npx envinfo --preset jest
in your project directory and paste the
results here
System:
OS: macOS High Sierra 10.13.3
CPU: x64 Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz
Binaries:
Node: 8.8.1
Yarn: 1.5.1
npm: 5.4.2
npmPackages:
jest:
wanted: ^22.4.2
installed: 22.4.2
Issue Analytics
- State:
- Created 6 years ago
- Reactions:15
- Comments:10
Top GitHub Comments
I’m doing this, thanks @kevinbarabash for the link.
I’m experiencing this when using
enzyme
’smount()
to render a component that throws in itsrender()
function. I’m guess it has something to do with the way thatjsdom
’s error handling works.