I am new to unit testing with Jest. I am testing a component in a React app. There are two components: Home
and LogOutButton
This is The Ho
A fix for your test is a little addition to what you already have.
delete window.location;
window.location = { reload: jest.fn() };
describe('Home', () => {
it('should click logout button', () => {
const component = Enzyme.mount( );
const logOutButton = component.find(LogOutButton);
logOutButton.simulate('click');
expect(window.location.href).toEqual('https://www.MICROSOFT.com');
});
});
You quickly notice I deleted window.location
as window.location
is not modifiable in Jest. That is the missing link.