How to make sure that the next/router is tested or mocked
itstheandre opened this issue ยท 3 comments
I am trying to run a test on my signup page.
I have tried looking into it in a e2e test and it checks that my next/router
works becuase I know that after a successful login the page is redirected.
The question is, how do I test it in my component testing?
Because, according to my code coverage report its the only part that is missing to be tested
.
Great great work on this!
you can see my repo for an idea:
https://github.com/itstheandre/cypress-test-react-learning/tree/next
Ok, this is a problem with the router returned from useRouter
- it actually swallows the error here
I have forked the repo to show the problem: https://github.com/bahmutov/cypress-test-react-learning/blob/master/next-cypress/cypress/components/signup.spec.jsx#L24
- clone https://github.com/bahmutov/cypress-test-react-learning
- cd next-cypress
yarn
- start Cypress using
yarn cypress open
- click on the component test 'signup.spec.jsx'
The test fails at the end when the component calls router.push('/')
Seems router = useRouter()
returns null
This might be related to #452 that also has router
Hey @bahmutov do you think it would be possible to mock the import? sort of what jest.mock
does?
๐ This issue has been resolved in version 4.15.0 ๐
The release is available on:
Your semantic-release bot ๐ฆ๐