Hi everyone,
I have learnt full stack web development for several months but am still struggling with testing. Are there any good resources for learning testing, especially with tools like Enzyme and Jest for beginners? Btw, anyone could explain how one should test fetch in a function component? I have found sth like below:
const mockSuccessResponse = {data:{...}};
const mockJsonPromise = await Promise.resolve(mockSuccessResponse);
const mockFetchPromise =await Promise.resolve({
json: () => mockJsonPromise,
});
jest.spyOn(global, 'fetch').mockImplementation(() => mockFetchPromise);
process.nextTick(() => {
expect(wrapper...).toBe(...)
global.fetch.mockClear();
done();
});
My question is in my functional component, there are several fetch functions,.Which one will be mocked with the above code?