This repository was archived by the owner on May 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathTodoDetail.test.tsx
More file actions
55 lines (52 loc) · 1.36 KB
/
TodoDetail.test.tsx
File metadata and controls
55 lines (52 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { screen } from "@testing-library/react";
import axios from "axios";
import { MemoryRouter, Navigate, Route, Routes } from "react-router";
import { renderWithProviders } from "../../test-utils/mock";
import TodoDetail from "./TodoDetail";
const renderTodoDetail = () => {
renderWithProviders(
<MemoryRouter>
<Routes>
<Route path="/todo-detail/:id" element={<TodoDetail />} />
<Route path="*" element={<Navigate to={"/todo-detail/3"} />} />
</Routes>
</MemoryRouter>,
{
preloadedState: {
todo: {
todos: [
{
id: 3,
title: "TODO_TEST_TITLE_3",
content: "TODO_TEST_CONTENT_3",
done: false,
},
],
selectedTodo: null,
},
},
}
);
};
describe("<TodoDetail />", () => {
it("should render without errors", async () => {
jest.spyOn(axios, "get").mockImplementation(() => {
return Promise.resolve({
data: {
id: 3,
title: "TODO_TEST_TITLE_3",
content: "TODO_TEST_CONTENT_3",
done: false,
},
});
});
renderTodoDetail();
await screen.findByText("TODO_TEST_TITLE_3");
await screen.findByText("TODO_TEST_CONTENT_3");
});
it("should not render if there is no todo", async () => {
renderTodoDetail();
jest.spyOn(axios, "get").mockImplementationOnce(() => Promise.reject());
expect(screen.queryAllByText("TODO_TEST_TITLE_3")).toHaveLength(0);
});
});