next-and-cypress-example icon indicating copy to clipboard operation
next-and-cypress-example copied to clipboard

Mocking `getInitialProps` Responses

Open mattfwood opened this issue 4 years ago • 2 comments

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!

mattfwood avatar Nov 11 '20 19:11 mattfwood

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

I have a workaround for you.

kylemh avatar Jan 12 '21 19:01 kylemh

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

fibonacid avatar Nov 08 '21 16:11 fibonacid