@@ -22,6 +22,16 @@ vi.mock("components/ComponentInjector", () => ({
2222 } ,
2323} ) ) ;
2424
25+ const mockSetTab = vi . fn ( ) ;
26+
27+ // Mock the useNewsFeed hook
28+ vi . mock ( "./useNewsFeed" , ( ) => ( {
29+ data : [ ] , // Assume empty data for simplicity
30+ isLoading : false ,
31+ isError : false ,
32+ setTab : mockSetTab ,
33+ } ) ) ;
34+
2535const user = userEvent . setup ( ) ;
2636
2737describe ( "News component" , ( ) => {
@@ -77,18 +87,16 @@ describe("News component", () => {
7787 } ) ;
7888 } ) ;
7989
80- it ( "calls the SetTabValue function with the correct argument when a tab is changed" , async ( ) => {
81- // Iterate over each tab item defined in TAB_ITEMS
82- TAB_ITEMS . forEach ( async ( tabItem , index ) => {
83- // Simulate clicking on the tab
84- await user . click ( tabs [ index ] ) ;
90+ it ( "calls setTab with the new tab value on tab change" , async ( ) => {
91+ // This example simulates clicking the second tab
92+ const secondTab = TAB_ITEMS [ 1 ] ;
93+ await user . click (
94+ screen . getByRole ( "tab" , { name : secondTab . label } )
95+ ) ;
8596
86- // Assert that mockSetTab was called with the 'key' of the current tabItem
87- expect ( mockSetTab ) . toHaveBeenCalledWith ( tabItem . key ) ;
88-
89- // Reset mock function history after each assertion to ensure independence
90- mockSetTab . mockClear ( ) ;
91- } ) ;
97+ // Verify setTab was called with the value of the second tab
98+ expect ( mockSetTab ) . toHaveBeenCalledWith ( secondTab . key ) ;
99+ mockSetTab . mockClear ( ) ;
92100 } ) ;
93101 } ) ;
94102} ) ;
0 commit comments