question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] How to use miragejs mocks with Playwright component tests?

See original GitHub issue

I’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:closed
  • Created a year ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
rwollcommented, Aug 11, 2022

@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.)

1reaction
pavelfeldmancommented, Aug 20, 2022

@VaasRamsay would you be open to contributing a docs page (markdown) providing this example?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found