Created
November 18, 2019 09:40
-
-
Save kisildev/2cd5b8613bb460e0087c7a1b91a23bc1 to your computer and use it in GitHub Desktop.
Jest test mock class method
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
it('should redirect to another page', () => { | |
const user = { | |
id: 1, | |
token: 'J9gj9fj90.Tgf84h8Ufds.jfiosdjfi', | |
}; | |
// static method | |
const spy = jest.spyOn(Login, 'redirectUser'); | |
mount(<Login user={user} />, global.contextData); | |
expect(spy).toBeCalled(); | |
// Method by Spy on | |
const mockRedirectUser = jest.spyOn(wrapper.instance(), 'componentDidMount'); | |
expect(mockRedirectUser).toHaveBeenCalled(); | |
// Method by jest.fn() | |
wrapper.instance().redirectUser = jest.fn(); | |
expect(wrapper.instance().redirectUser).toBeCalled(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment