Replies: 4 comments
-
I also have this same question, is there any way to do this with Jest and ReactTestingLibrary? The use mutate function is what is called last and will help validate the test completed successfully. |
Beta Was this translation helpful? Give feedback.
-
Hi there! I have the same question. I think it will give my component for confidence if I can spy on the mutate method and check that it is called and it is called with specific parameters. What I have tried so far which did not work:
The tests is failing with that mutate has been called 0 times. I appreciate any help or ideas. |
Beta Was this translation helpful? Give feedback.
-
Unfortunately, still solution needed.
Would appreciate any suggestions. |
Beta Was this translation helpful? Give feedback.
-
I found this solution: jest.mock('react-query', () => ({ const mockMutationFn = { mutate: () => mockedMutate() }; expect(mockedMutate).toHaveBeenCalled(); |
Beta Was this translation helpful? Give feedback.
-
Hi! I'm attempting to spy on the bound/local mutate function to ensure it was called during a test (jest).
I'm calling useSWR like so:
The test is something like the following. Previously I was using the global mutate function with a parameter:
What's the best way for me to test that
mutateMe
was called via a test, without mocking the entireuseSWR
hook? I'm currently using version 1.1.2 of SWR, but if that's a limiting factor to a solution, happy to upgrade to the newest version.Thanks in advance for any guidance.
Beta Was this translation helpful? Give feedback.
All reactions