vulcan-next icon indicating copy to clipboard operation
vulcan-next copied to clipboard

Use MSW for API mocking in tests

Open eric-burel opened this issue 4 years ago • 2 comments

Is your feature request related to a problem? Please describe. Mocking graphql queries is annoying, and we use specific solution.

Describe the solution you'd like Use the same lib for all frontend request mocks.

  • [X] Drafted a first example in Storybook, for the SmartForm (FormContainer) in Vulcan NPM
  • [ ] Check that preview.js still loads correctly in Jest after adding msw
  • [ ] Extend install to Jest, by creating a server on startup
  • [ ] Cleanup reusable helper (declarative mocks to MSW mocks)
  • [ ] Add MSW to Cypress? We already have cy.intercept but MSW might be used to intercept ssr requests as well
  • [ ] Add MSW in both Vulcan Next and Vulcan NPM

Describe alternatives you've considered Apollo Mock Client: not bad. But MSW seems to become the standard for both Rest and graphql, because it catches calls at a lower level: https://mswjs.io/docs/getting-started/mocks/graphql-api

Additional context Testing with Next discussion: https://github.com/vercel/next.js/discussions/28173#discussioncomment-1281150

eric-burel avatar Sep 06 '21 07:09 eric-burel

MSW also work for API:https://github.com/vercel/next.js/tree/canary/examples/with-msw

eric-burel avatar Oct 04 '21 07:10 eric-burel

Done for Vulcan NPM, needs to be copied over Vulcan Next

eric-burel avatar Mar 11 '22 16:03 eric-burel