swr tests - mock useSWRConfig implementation
Is there a way to mock implementation of useSWRConfig
hook from swr in jest test?
import useSWR, { useSWRConfig } from 'swr';
it('should mutate', () => {
const mutation = jest.fn();
useSWR.mockImplementationOnce(() => ({ error: true })); // this works
useSWRConfig.mockImplementationOnce(() => ({ mutation })); // TypeError: _swr.useSWRConfig.mockImplementationOnce is not a function
expect(mutation).toHaveBeenCalled(); // not working
});
Docs: https://swr.vercel.app/docs/mutation
from Recent Questions - Stack Overflow https://ift.tt/3moS7FA
https://ift.tt/eA8V8J
Comments
Post a Comment