You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description: when you enable overwriteRoutes, and mock a route twice with a RegExp, it will not mock with the response of the second mock unless you share the same RegExp instance.
Reproduction:
importfetchMockfrom'fetch-mock'fetchMock.config.overwriteRoutes=trueit('foo',()=>{fetchMock.mock(/example\.com/,200)constsuccessResponse=awaitfetch('example.com')expect(successResponse.status).toBe(200)fetchMock.mock(/example\.com/,404)constfailureResponse=awaitfetch('example.com')expect(failureResponse.status).toBe(404)// nope, its 200})
I narrowed this problem down to some code that did a triple equality check but I don't remember where I saw it. That would explain though why a shared reference works, but the earlier one doesn't.
The text was updated successfully, but these errors were encountered:
ryuuji3
changed the title
regexp matchers cannot be overwritten
regexp matchers cannot always be overwritten
Mar 8, 2021
I think this is expected behaviour, though I agree it's not obvious and not documented very well.
To get more transparent behaviour it's best to name your routes
it('foo',()=>{fetchMock.mock(/example\.com/,200,{name: 'myroute'})constsuccessResponse=awaitfetch('example.com')expect(successResponse.status).toBe(200)fetchMock.mock(/example\.com/,404,,{name: 'myroute'})constfailureResponse=awaitfetch('example.com')expect(failureResponse.status).toBe(404)// should be 404})
Version: latest
Description: when you enable overwriteRoutes, and mock a route twice with a RegExp, it will not mock with the response of the second mock unless you share the same RegExp instance.
Reproduction:
If, however you amend the above to
it works as expected.
I narrowed this problem down to some code that did a triple equality check but I don't remember where I saw it. That would explain though why a shared reference works, but the earlier one doesn't.
The text was updated successfully, but these errors were encountered: