You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I clicked the button, the mutation process started.
and I successfully tested that the mutation was executed.
However, I failed to test the UI changes after the mutation.
I confirmed that the UI did not change after the mutation.
Is there a problem with my testing method?
// notifictaion.test.tsxvi.mock('@/components/notification/queries',()=>({useDeleteNotification: vi.fn(),}));constmockedDeleteMutate=vi.fn();vi.mocked(useDeleteNotification).mockReturnValue({mutate: mockedDeleteMutate,});constqueryClient=newQueryClient({defaultOptions: {queries: {retry: false,},},});constwrapper=({ children }: {children: ReactNode})=>{return(<QueryClientProviderclient={queryClient}>{children}</QueryClientProvider>);};test('delete notification',async()=>{render(<Notification/>,{ wrapper });constuser=userEvent.setup();// I also mocked the API that fetches 6 data items, but I omitted that part in my explanation.constnotifications=awaitscreen.findAllByRole('figure',{name: /notification/,});expect(notifications).toHaveLength(6);// delete_button_1 => notification id is 1constbutton=screen.getByRole('button',{name: /delete_button_1/});awaituser.click(button);// passawaitwaitFor(()=>{// notification id is 1expect(mockedDeleteMutate).toHaveBeenCalledWith(1);});});// not passawaitwaitFor(()=>{constnotifications=awaitscreen.findAllByRole('figure',{name: /notification/,});expect(notifications).toHaveLength(5);})
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I mocked the network call for the mutation using MSW and wrote the mutation hook.
test code
When I clicked the button, the mutation process started.
and I successfully tested that the mutation was executed.
However, I failed to test the UI changes after the mutation.
I confirmed that the UI did not change after the mutation.
Is there a problem with my testing method?
feature code
Beta Was this translation helpful? Give feedback.
All reactions