[Question] How to use miragejs mocks with Playwright component tests?
See original GitHub issueI’ve been playing around with Playwright Component tests, and am struggling to wire up miragejs
mock server with the test suite. Is there a recommended approach/solution to this?
My frontend app uses CRA and has a miragejs
mock server for testing. What’s the right way to initialize this in Playwright component tests?
Note: For comparison, this is how Cypress wires it up. I’ve tried adding a proxy function like the one Cypress uses via context.addInitScript
before the test begins. I can see the function being attached to the window object, but redirect from the app doesn’t seem to work.
Issue Analytics
- State:
- Created a year ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Integration and unit tests - Mirage JS
Let's say you have a data-fetching component, and you want to write a test to verify its behavior. You could use the startMirage...
Read more >Mocking API call using miragejs for Playwright testing
I have a miragejs server running during the test and playwright tests make use of it and evrything works as expected.
Read more >4 ways to fake an API in frontend development
Another option is to import Mirage JS only in testing. Takeaways: use MirageJS to mock API calls in development or testing. It's mocking...
Read more >Getting started with Playwright component testing
Let's explore the recently-introduced Playwright component testing feature, using it to test React, Vue, and Svelte components in an app.
Read more >e2e testing setup and thoughts on Playwright - Reddit
Question : does your org force e2e tests as a required CI step prior to ... during development we use mirage JS to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@VaasRamsay Thanks for your patience! It’s possible to do this functionality, but in order to give you a better answer, we’ll need some more time to play around.
I’ve assigned this out and marked to the next milestone so we can hopefully dedicate some time to it. (It hits on topics beyond just network mocking—e.g. running code in browser vs. in node—and what to do where when, so there’s probs some more holistic education/docs we can add here.)
@VaasRamsay would you be open to contributing a docs page (markdown) providing this example?