Im still new to unit tests and im struggling to understand how i could test/mock a push from a router,
<Tab label="Members" alt="Members" onClick={() => Router.push('/members')}/>
the above line is what i need to test but how could i? would i create a fake end point and then test the onClick?
The easiest thing would be to mock the router like this
import Router from 'next/router'
jest.mock('next/router', ()=> ({push: jest.fn()}))
after simulate the click on Tab you can check for the call like this
expect(Router.push).toHaveBeenCalledWith('/members')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With