Last active
September 6, 2022 14:07
-
-
Save danielr1996/5478d3eeaa6883c814fee0378c3b6d7c to your computer and use it in GitHub Desktop.
Test React hook which uses another hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {useExternal} from "./useExternal"; | |
const useInternal = jest.spyOn(require('./useInternal'), 'useInternal') | |
useInternal.mockReturnValue(2) | |
test('useExternal', ()=>{ | |
const actual = useExternal() | |
const expected = 4 | |
expect(actual).toBe(expected) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {useInternal} from "./useInternal"; | |
export const useExternal = ()=>{ | |
const number = useInternal() | |
return number *2 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const useInternal = ()=>{ | |
return -1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment