useMutation Testing using Vitest
Hello, I want to generated different responses or states based on a specific mutation that is happening in my component.
is there a way that I can do that for different testing scenarios that I have to test in this component?
for example:
I want to test that a loader appears when the useMutation is on a loading state.
Or that useMutation has data and the screen of success is show.
I have made this mock:
vi.mock('@tanstack/react-query', async () => {
const actualModule = await vi.importActual('@tanstack/react-query');
return {
...actualModule,
useMutation: vi.fn(() => ({
mutate: vi.fn(),
isPending: true,
isError: false,
}))
};
});
but only covers 1 case the loading for example
0 Replies