jest-fail-on-console icon indicating copy to clipboard operation
jest-fail-on-console copied to clipboard

Is there a way to not fail a test on console.error, but still print?

Open billyvg opened this issue 2 years ago • 2 comments

I would still like to see the console.error message when it happens, but be able to have the test not fail.

billyvg avatar Sep 14 '22 18:09 billyvg

What you are looking for might be achievable by using the skipTest option: https://github.com/ValentinH/jest-fail-on-console#skiptest

ValentinH avatar Sep 15 '22 14:09 ValentinH

Afaict, there is no way currently to emit the warning, but not fail the test. If you would like to submit a PR, you'd want to take an option, and then use that to determine whether or not to throw here

doug-wade avatar Oct 11 '22 21:10 doug-wade

This library could call the original console method, as following:

console[methodName] = (...args) => {
  newMethod(...args);
  originalMethod(...args);
}

That makes sense to me: the goal of this library is to fail the tests under some conditions, not to alter what is printed is the console.

clemp6r avatar Aug 08 '23 15:08 clemp6r

I like this idea. We could add this behavior as a new option and make it the default. We would then release a new major version.

ValentinH avatar Aug 09 '23 13:08 ValentinH

I would love this functionality as well.

My use case is that I have multiple tests where console.error is called, but I cannot control when it gets called as the code being executed is outside of my control.

I'd really like to have the option to:

  1. Fail tests if the output of the console[method] call matches on certain text
  2. Output all other console messages (even errors) and not fail

I can potentially submit a PR if you could point me in the right direction

vernak2539 avatar Feb 05 '24 14:02 vernak2539

I think that @clemp6r proposal is good. We could change the default behavior to let all logs go to the console and only make the test fail.

ValentinH avatar Feb 05 '24 16:02 ValentinH

@ValentinH I've opened https://github.com/ValentinH/jest-fail-on-console/pull/48 and would appreciate any feedback you have

vernak2539 avatar Feb 06 '24 12:02 vernak2539