score:3

Instead of mocking next/link you can register a spy on router events, and check if it was called.

The test will look like this:

import Router from 'next/router';

describe('Test of <HeaderContainer>', () => {
  const spies: any = {};

  beforeEach(() => {
    spies.routerChangeStart = jest.fn();
    Router.events.on('routeChangeStart', spies.routerChangeStart);
  });

  afterEach(() => {
    Router.events.off('routeChangeStart', spies.routerChangeStart);
  });

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

    expect(spies.routerChangeStart).toHaveBeenCalledWith('expect-url-here');
  });
});

Related Query

More Query from same tag