Open kataik opened 4 years ago
Btw, directly deleting the require cache also has no effect.
Sounds like you need to "cancel" the first line of your example.
I call forceCacheClear(false/true/'nocache') to restore B
no, forceCacheClear
is only about different modes to handle cache, while you have to cancel mocking. Probably you need
rewiremock.clear()
. It just clears everythinginScope
helpers (rewiremock.proxy
included), which does not affect anything around themrewiremock
in a wrong way - it is expected to "autoclear" itself from the cache, if imported directly, or if overrideEntryPoint is in use
Sorry in advance if I misunderstood the concept.
I have the following module dependencies:
A -> B B -> C
I have unit tests for module A and B (executed in this order by mocha). In A's tests I use
rewiremock
to mock B and in B's unit tests I mock C the same way. Before running tests for B, I callforceCacheClear(false/true/'nocache')
to restore B so I am able to require the original B module betweenrewiremock.enable()
andrewiremock.disable()
calls.My issue is that whatever I do, B is resolved to the already mocked version of it when it gets executed after A's unit tests.
A simplified example (module main's default function originally returns
'foo'
):Btw, directly deleting the require cache also has no effect.
Can you please point me the right direction on how to isolate my mock states for my unit tests? Any help is greatly appreciated.