Closed tejohnso closed 3 years ago
Yes, the destructuring happens at module load time, which is before the mocking happens. Had the destructuring been inside the function, it would happen at run time, which should be after mocking.
Yeah. It would be nice to be able to use destructuring at module load time while still being able to mock. But I'll just go ahead and close this :)
When using object destructuring on the require object, the mock doesn't work. I'm not sure this is fixable as there is no longer a reference to a mocked object property during test runtime.
Test
Code Under Test in target.js (NOT working with destructuring on first line)
Code Under Test in target.js (Works without destructuring)