I was confused, why we have const fetchMock in beforeEach but then reference fetchMock in the test, it should be undefined there, outside of the scope. Turns out it was because fetchMock is also a global variable. Looking at type definitions, I see that createFetchMock is also called createMocker. So I think it'll make more sense to do this:
This way there's no clash and it makes more sense - you create fetchMocker, then fetchMocker.enableMocks() will define global fetchMock for you. Hope this makes sense!
I was reviewing code at work and I saw this:
I was confused, why we have
const fetchMock
inbeforeEach
but then referencefetchMock
in the test, it should be undefined there, outside of the scope. Turns out it was becausefetchMock
is also a global variable. Looking at type definitions, I see thatcreateFetchMock
is also calledcreateMocker
. So I think it'll make more sense to do this:This way there's no clash and it makes more sense - you create
fetchMocker
, thenfetchMocker.enableMocks()
will define globalfetchMock
for you. Hope this makes sense!