3

Is there a way in a Cypress test to stub a GraphQL query called with Next.JS getServerSideProps?

I have tried using cy.intercept, but, being the request done server side, cy.intercept doesn't seem to intercept it.

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
Giovanni
  • 177
  • 1
  • 2
  • 8
  • Might be worth having a look at [mocking server for SSR react app e2e tests with cypress.io](https://stackoverflow.com/questions/47631821/mocking-server-for-ssr-react-app-e2e-tests-with-cypress-io). – juliomalves Jul 19 '21 at 21:22
  • 1
    I have manage to stub it successfully using [Mock Service Worker](https://mswjs.io/), but I have no way to change the returned mock before each test. When setting a handler with MSW it is set before cypress open...then I can't manage to `resetHandler` for a `serverWorker` from a test running instead in the browser. – Giovanni Sep 23 '21 at 14:30

1 Answers1

0

You can use something like 'nock' which will spin up a BE server, and allow you to set up the responses to return when getServerSide executes as part of the cypress page test

Tom Chamberlain
  • 2,955
  • 20
  • 24