Skip to content

Commit 359c4f8

Browse files
committed
なぜかエラー
1 parent 317434d commit 359c4f8

File tree

1 file changed

+50
-6
lines changed

1 file changed

+50
-6
lines changed

src/__tests__/Contributors.spec.tsx

+50-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { render,screen} from "@testing-library/react";
1+
import { render, screen } from "@testing-library/react";
22
import { ChakraProvider } from "@chakra-ui/react";
33
import { Contributors } from "../components/Contributors";
44
import { act } from "react";
5+
import userEvent from "@testing-library/user-event";
56

6-
7+
// firebase関数のモック化
78
jest.mock("firebase/app", () => ({
89
initializeApp: jest.fn(),
910
}));
@@ -13,6 +14,22 @@ jest.mock("firebase/auth", () => ({
1314
}),
1415
}));
1516

17+
const mockGetSubjects = jest
18+
.fn()
19+
.mockResolvedValue([{ id: 1, year: 1, name: "離散数学" }]);
20+
21+
// supabase関数のモック化
22+
jest.mock("../lib/supabasefunctions", () => {
23+
return {
24+
getSubjects: () => mockGetSubjects(),
25+
getSubjectUserIds: jest.fn(),
26+
getUserInfo: jest.fn(),
27+
// addUser: jest.fn(),
28+
// updateUserInfo: jest.fn(),
29+
// addUserToSubject: jest.fn()
30+
};
31+
});
32+
1633
describe("過去問の募集投稿ページのテスト", () => {
1734
beforeEach(() => {
1835
render(
@@ -28,17 +45,17 @@ describe("過去問の募集投稿ページのテスト", () => {
2845

2946
test("バリデーションエラーが表示される", async () => {
3047
const postButton = screen.getByTestId("kakomon-register-modal");
31-
48+
3249
await act(async () => {
3350
postButton.click();
3451
});
35-
52+
3653
const submitButton = await screen.findByTestId("kakomon-register-button");
37-
54+
3855
await act(async () => {
3956
submitButton.click();
4057
});
41-
58+
4259
expect(
4360
await screen.findByText("⚠️お名前は必須入力項目です。")
4461
).toBeInTheDocument();
@@ -50,4 +67,31 @@ describe("過去問の募集投稿ページのテスト", () => {
5067
).toBeInTheDocument();
5168
});
5269

70+
test("過去問を登録できる", async () => {
71+
const postButton = screen.getByTestId("kakomon-register-modal");
72+
await act(async () => {
73+
postButton.click();
74+
});
75+
const submitButton = await screen.findByTestId("kakomon-register-button");
76+
expect(submitButton).toBeInTheDocument();
77+
78+
const nameInput = await screen.findByTestId("name-input");
79+
await act(async () => {
80+
await userEvent.type(nameInput, "テスト太郎");
81+
});
82+
const kakaoIdInput = screen.getByTestId("kakaoId-input");
83+
await act(async () => {
84+
await userEvent.type(kakaoIdInput, "test-id");
85+
});
86+
87+
const subjectNameInput = screen.getByTestId("subjectName-input");
88+
await act(async () => {
89+
await userEvent.type(subjectNameInput, "離散数学");
90+
});
91+
await act(async () => {
92+
submitButton.click();
93+
});
94+
95+
});
96+
5397
});

0 commit comments

Comments
 (0)