Closed trixn86 closed 3 years ago
Sorry for the slow response.
I like the API idea, but it feels like a massive departure from the current implementation and probably difficult to achieve. Would require massive amounts of writing new tests for the library (or, rather, for fetch-mock) too.
So realistically I can't see it happening, but will keep it open in case I think of a way.
For fetch-mock there is an easier naming API coming soon probably
fetch.mock(url, response, 'my-name');
expect(fetchMock).toHaveFetchedTimes('my-name');
In fact, even now, you should be able to use 'my-name' instead of {name: 'my-name'}
in assertions anyway
First of all thanks for your awesome library. It makes life much easier when testing my react components that perform API calls.
While experimenting with asserting one question came up. Would it be possible to let
fetchMock.mock()
return a new mock that only tracks fetch calls where the givenfilter
andoptions
apply so I can assert like that? :As far as I understood this can currently be achieved like that using a
name
......but it doesn't feel as natural to me as I need to use strings to reference a certain fetch calls. Also this is error prone and can make my tests fail because of typos in the
name
or accidentally reusing aname
and it is lacking auto-completion.What do you think about the proposed api and do you think it is hard to implement?