I've got a library that's giving me some trouble in my jest tests.
This library is included throughout my project, and it has an annoyingFunction
that has a console.error
in it. So, whenever I run a test, I naturally get unwanted console.error
messages all over the place.
I don't want to mock out the whole library, just the annoyingFunction
, so I put this in my setup file:
jest.mock('myLibrary', () => ({
...jest.requireActual('myLibrary'),
annoyingFunction: jest.fn(),
}));
This is being run, however, the original annoyingFunction
is still being called, polluting my tests with console.error
calls.
If I console log my mock, I clearly see annoyingFunction: [Function: mockConstructor]
, so the mock is working, but for some reason, the original function from the library is still being called.
What am I missing here? Is there something wrong with my initial setup of the mock?