Thanks to @sdgluck for the answer, though I would like to add to this answer that in my case, I wanted a clear state after each tests since I have multiple tests with same spy. So instead of calling the mockClear()
in previous test(s), I moved it into the afterEach()
(or you can use it with beforeEach
) like so:
afterEach(() => {
jest.clearAllMocks();
});
And finally, my tests are working like they should without the spy being called from previous test. You can also read their documentation for it
Option 2
If you wish to do it from a global level, you could also updated your jest.config.js
(or from package.json
)
module.exports = {
clearMocks: true,
// ...
}
You can read Jest documentation about it