Reputation: 5660
I have a react
component which navigates to a different pages based on the value of somecondition. For example:
if (somecondition) {
window.location.assign('some link')}
}
How would I test this somecondition using enzyme
wrapper ?
Upvotes: 1
Views: 662
Reputation: 17332
Using enzyme and jest, your test could look like this:
test('should redirect', () => {
// SETUP
window.location.assign = jest.fn()
// EXECUTE
const wrapper = shallow(<Component {...props} />)
wrapper.instance().callYourFunction()
// VERIFY
expect(window.location.assign).toHaveBeenCalled()
window.location.assign.mockClear()
})
Upvotes: 2