New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow console.error/warn/log to be overwritten in tests #3239
Comments
Use mocking function console.warn = jest.fn(warn => {
throw new Error(warn);
}); |
@thymikee This isn't working as expected either, using a global setup file: in
In test:
|
i just tried it and it worked: // test file
test('lol', () => {
return new Promise((resolve) => {
console.log('lol');
resolve();
});
}); // setup file
global.console.log = () => {
throw new Error('hey!');
}; result:
|
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Do you want to request a feature or report a bug?
feature
What is the current behavior?
Due to the
BufferedConsole
, it's impossible to overwriteconsole.error
,console.log
,console.warn
andconsole.info
.Use Case: We'd like to be able to have
console.error
andconsole.warn
throw errors and fail tests.If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can
yarn install
andyarn test
.What is the expected behavior?
I expect that if I add
console.error = (message) => { throw new Error(message); };
(globally, in a test, or in setupFiles/setupFramework), that any timeconsole.error
is called in a test it would throw an error and fail a test.In reality, nothing happens.
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
N/A
The text was updated successfully, but these errors were encountered: