I am writing unit tests with Jest and Enzyme. I have a button on a 404 page which should redirect a user to the websites homepage. I want to write a test to make sure this button is redirecting a user to the homepage regardless of the URL. In other words the test should pass if the button click takes a user to the homepage and should not rely on the href.
So far I have the code to click my button which should reroute the user.
it('redirects when HOMEPAGE button is clicked', () => {
const wrapper = mount(<PageNotFound />);
const link = wrapper.find('#page-not-found-link').first();
link.simulate('click');
expect()
})
When the button is clicked we should be routed to <HomePage />
so I have tried adding in:
it('redirects when HOMEPAGE button is clicked', () => {
const wrapper = mount(<PageNotFound />);
const newComp = mount (<HomePage />);
const link = wrapper.find('#page-not-found-link').first();
const buttonClick = link.simulate('click');
expect(buttonClick).toEqual(newComp)
})
It seems like I need to compare <HomePage />
with the result of clicking the button but I haven't been able to find a working solution yet.