Skip to content

Commit 5562741

Browse files
committed
test: fixing tests
1 parent 8e82911 commit 5562741

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/2024/Speakers/Speakers2024.test.tsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,22 @@ vi.mock("react-use", () => ({
2020
vi.mock("@sentry/react", () => ({
2121
captureException: vi.fn(),
2222
}));
23-
vi.mock("@data/2024.json", () => ({
23+
vi.mock("@data/2024.json", () => {
24+
return {
25+
default: {
26+
hideSpeakers: false,
27+
edition: "2024",
28+
title: "DevBcn",
29+
cfp: {
30+
startDay: "2023-01-01T00:00:00",
31+
endDay: "2023-02-01T00:00:00",
32+
link: "https://example.com/cfp",
33+
},
34+
},
35+
};
36+
});
37+
38+
const initialMock2024Data = {
2439
hideSpeakers: false,
2540
edition: "2024",
2641
title: "DevBcn",
@@ -29,7 +44,8 @@ vi.mock("@data/2024.json", () => ({
2944
endDay: "2023-02-01T00:00:00",
3045
link: "https://example.com/cfp",
3146
},
32-
}));
47+
};
48+
const mutableMock2024Data = { ...initialMock2024Data };
3349

3450
const mockedUseFetchSpeakers = useFetchSpeakers as MockedFunction<
3551
typeof useFetchSpeakers
@@ -78,25 +94,21 @@ describe("Speakers2024 component", () => {
7894
});
7995

8096
it("displays a message when hideSpeakers is true", () => {
81-
// Mock the hook to return success state with data
8297
mockedUseFetchSpeakers.mockReturnValue({
8398
data: [],
8499
isLoading: false,
85100
error: null,
86101
isSuccess: true,
87102
});
88103

89-
// Temporarily override the hideSpeakers value
90-
const originalModule = jest.requireMock("../../data/2024.json");
91-
const originalHideSpeakers = originalModule.hideSpeakers;
92-
originalModule.hideSpeakers = true;
104+
// Modify the hideSpeakers property of our mutable mock data
105+
mutableMock2024Data.hideSpeakers = true;
93106

94107
renderWithRouterAndQueryClient(<Speakers2024 />);
95108

96109
expect(screen.getByText(/No selected speakers yet/i)).toBeInTheDocument();
97110

98-
// Restore the original value
99-
originalModule.hideSpeakers = originalHideSpeakers;
111+
// No need to manually restore here; beforeEach will reset it for the next test.
100112
});
101113

102114
it("calls useFetchSpeakers with the correct year", () => {

0 commit comments

Comments
 (0)