'jest mockReturnValueOnce is not a function
I have a custom hook that returns true or false by checking if the view is a mobile or a desktop view.
I'm trying to write a test for a page that uses this hook. I tried as following
import { useIsMobile } from '../../../../hooks/useIsMobile';
jest.mock('../../../../hooks/useIsMobile');
describe('Form', () => {
beforeEach(jest.resetAllMocks);
it('should render the correct header style for deliver to label in desktop view', () => {
(useIsMobile as jest.Mock).mockReturnValueOnce(false);
const delivery_label = screen.getByTestId('label1');
expect(delivery_label.tagName).toEqual('H3');
});
it('should render the correct header style for deliver to label in mobile view', () => {
(useIsMobile as jest.Mock).mockReturnValueOnce(true);
const delivery_label = screen.getByTestId('label1');
expect(delivery_label.tagName).toEqual('H4');
});
}
But I'm getting this error
TypeError: _useIsMobile.useIsMobile.mockReturnValueOnce is not a function
What does this mean and how can i fix this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
