dimanche 15 mars 2020

How do I test next/link (Nextjs) getting page redirect after onClick in React?

I want to test the page get redirected after click on div, but I dont know how, this is my code. Thank you so much

<div className="bellTest">
   <NextLink href="/notifications">
       <Bell />
   </NextLink>
 </div>

test.tsx

jest.mock('next/link', () => {
     return ({ children }) => {
            return children;
     };
});

describe('Test of <HeaderContainer>', () => {
    test('Test the page redirect after click', async done => {
        const wrapper = mount( < HeaderComponent / > );
        await wrapper
            .find('.bellTest')
            .at(0)
            .simulate('click');
        // expect the page getting redirect
    });
});

Aucun commentaire:

Enregistrer un commentaire