Hide console.error when mocking error response in jest?
I'm writing a few client-side unit tests and want to assert what happens when an error is returned from the procedure.
My tests pass ok, but I end up with a wall of
console.error
's when I do so.
I don't want to mock the return value of console.error
so that it never fires, as there may be some valid errors that are thrown that I want to catch, especially when running my tests on my CI/CD.
Is there any other way to prevent the console.error
from logging when a procedure throws an error?
I've tried updating my loggerLink
in my config during testing so that it is disabled, like so;
While this does clear the likes of the following console.error
's
I will still get the likes of
Any help would be greatly appreciated!1 Reply
I haven't done this, but I've had the same problem and would be interested in finding out what others have done
Spitballing here...
- I could imagine maybe writing your own
it.silent
function that runs the test you pass it, but stubs out error printing and restores it after?
- Override toString
as a noop just for the error classes that you expect to be thrown?
- Patch jest.fn
, mockImplementation
, and mockRejectedValue
to intercept the error and re-throw it with some added property that will tell your logger/console to ignore it?