Playwright testing with Server Side Fetches #5145
Replies: 4 comments 3 replies
-
|
Any updates here? |
Beta Was this translation helpful? Give feedback.
-
|
You can use tools like mswjs to mock your servercalls. |
Beta Was this translation helpful? Give feedback.
-
|
I wrote a package to do this. The setup is more involved than I would like, but it solved my issue with Playwright tests hitting production API requests during E2E tests. https://github.com/markjaquith/sveltekit-playwright-fetch-mock |
Beta Was this translation helpful? Give feedback.
-
|
Use MSW as per Spuxx wrote here. @mabentley85 was your question answered yet? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When running Playwright tests, setting up mock API routes is pretty straight forward as per this simple example test:
When testing the page below it runs fine, as the API request is run in the browser:
But with this page, the test times out, as it's looking for the actual URL and is not intercepted by the mock API endpoint:
Are there any ways to configure Playwright and/or SvelteKit in order to intercept server side fetches so that mock data is returned?
Beta Was this translation helpful? Give feedback.
All reactions