Slide 19
Slide 19 text
© ZOZO, Inc.
19
共通で使われるカスタムフック
test("記事情報の取得中isLoadingはtrueになり、取得後はfalseになる", async () => {
const articles = generateMockArticles({ category: "react", length: 3 });
server.use(
rest.get(buildEndpoint("react"), (req, res, ctx) => {
return res(ctx.json(articles));
})
);
render();
expect(screen.getByTestId("loading")).toBeInTheDocument();
expect(await screen.findByTestId("loading")).not.toBeInTheDocument();
expect(screen.getAllByTestId("article").length).toBe(3);
});
● getByTestId メインで利用して要素を掴んでいる
● renderHook だと loading 状態のテストが難しいがコンポーネントだと書くことができる