bahmutov / next-and-cypress-example

Next.js example instrumented for code coverage from Cypress tests
140 stars 25 forks source link

Mocking `getInitialProps` Responses #116

Open mattfwood opened 3 years ago

mattfwood commented 3 years ago

Is it possible to mock / stub requests sent from getInitialProps or getServerSideProps? I've tried using cy.route and cy.route2 but I don't think it works since it's expecting to mock through the network layer in the browser.

Not sure if there's a way to do this or if there's a recommended practice? If there is one, I'd be glad to add it as an example in this repo.

Thanks!

kylemh commented 3 years ago

https://github.com/cypress-io/cypress/issues/4614

I have a workaround for you.

fibonacid commented 2 years ago

Apparently you can run next as a cypress plugin to mock server side network calls https://glebbahmutov.com/blog/mock-network-from-server/