@@ -20,7 +20,22 @@ vi.mock("react-use", () => ({
2020vi . 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
3450const 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 ( / N o s e l e c t e d s p e a k e r s y e t / 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