vulcan-next
vulcan-next copied to clipboard
Use MSW for API mocking in tests
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
MSW also work for API:https://github.com/vercel/next.js/tree/canary/examples/with-msw
Done for Vulcan NPM, needs to be copied over Vulcan Next