'how to mock useUser this custom hook using TypeScript
Let's say we have a custom hook named useUser
const useUser = (): IUser => useContext(MiniAppContext).user;
Then it is used in another component
import { useUser } from '@ABC'
const { monitoring } = useUser(); // please note that monitoring is an object having property id
When we run test case, it shows
TypeError: xxxx.useUser is not a function
I used below codes to pass the unit test, but I know that this is good enough. Please let me know what the best practise for this. Thanks in advance.
Update:
jest.mock('@ABC', () => ({
userUser: () => ({monitoring: {}} as IUser)
}));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
