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.
