Skip to content
Advertisement

Jest change mock implementation for a POJO module between tests

I am trying to mock the import of a Plain Old Javascript Object in a test, where I want different implementations for each test.

If I mock at the top of the file it works as expected:

JavaScript

But I cannot find any combination of doMock, default over named exports, mockImplementation to get the following to work:

JavaScript

Edit 1

Based on @jonrsharpe I have tried

JavaScript

Advertisement

Answer

Worked it out, the trick is to import/require the file under test (not the mocked file) AFTER setting the mock in the individual test. No import at the top of the file.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement