May 2019
Intermediate to advanced
496 pages
10h 38m
English
There's one more thing we can do to simplify our spies.
When we stubbed out window.fetch, we saved the original value in a variable named originalFetch. We then reset window.fetch to use that value in afterEach. Jest can simplify this for us with the jest.spyOn function. It stores the old value within Jest so we don't need to define the additional originalFetch variable.
The only complication of using this function is that the value we're mocking needs to already exist as a function. No big deal you might think. But if you remember, window.fetch isn't ever defined in our test module because we polyfilled it in src/index.js and that file is never imported.
So you can decide which you prefer: either an ...
Read now
Unlock full access