Malcolm Laing
Nov 7 · 1 min read

I have found the opposite, to be honest. I didn’t mention testing because I find them to be about equal. In the past, I have used jest-mock-fetch and it’s worked out fine for my use cases.

I made a full stack React app for a previous article. Here is App.test.js.

Here is an example of one of the test cases.

describe("deleting", () => {
it("should be able to delete", async () => {
fetch
.once(JSON.stringify([{ id: "1", name: "Harry Potter" }]))
.once(JSON.stringify({}));
const { getByText } = render(<App />);
await waitForElement(() => getByText("Harry Potter"));getByText("Delete").click();
getByText("Confirm?").click();
await waitForElementToBeRemoved(() => getByText("Harry Potter"));
});
});

As you can see, it’s pretty straightforward.

Here’s the blog post about setting up testing with fetch and React.

    Malcolm Laing

    Written by

    Front End Engineer in Berlin. Loves React, building component libraries, module bundling, and testing.

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade