November 2019
Beginner
804 pages
20h 1m
English
Now that we've seen how to test asynchronous code, let's see how we can test the getAllCountries method, which uses the Fetch API. For this one, we'll use our Fetch mock:
describe('getAllCountries', () => {
beforeEach(() => {
fetchMock.resetMocks();
});
// TODO add tests here
});
In the beforeEach function, we use jest-fetch-mock to reset the Fetch API mock. This is useful to avoid side effects between our test cases.
const dummyValidData: WorldBankApiV2CountryResponse = [{"page": 1, "pages": 7, "per_page": "50", "total": 304}, [{ "id": "ABW", "iso2Code": "AW", "name": ...Read now
Unlock full access