Unverified Commit 6b58c956 authored by Aria's avatar Aria Committed by GitHub

Update documentation for experimental Playwright test mode + msw v2 (#71841)

Next.js 15 updated `msw` from 1.3.0 to 2.3.0
(https://github.com/vercel/next.js/pull/66351), this PR updates the
example in the experimental Playwright test mode documentation to
reflect this.

Additionally:
- Added catch-all passthrough route to example.
- Fixed issue in the example with how `mswHandlers` was used
(https://playwright.dev/docs/test-fixtures#fixtures-options)

Relevant discussions:

https://github.com/vercel/next.js/issues/71832

https://github.com/vercel/next.js/discussions/71330

---------
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent 88238fb5
......@@ -72,30 +72,37 @@ test('/product/shoe', async ({ page, next }) => {
### Or use the `next/experimental/testmode/playwright/msw`
```javascript
import { test, expect, rest } from 'next/experimental/testmode/playwright/msw'
import {
test,
expect,
http,
HttpResponse,
passthrough,
} from 'next/experimental/testmode/playwright/msw'
test.use({
mswHandlers: [
rest.get('http://my-db/product/shoe', (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
[
http.get('http://my-db/product/shoe', () => {
return HttpResponse.json({
title: 'A shoe',
})
)
}),
}),
// allow all non-mocked routes to pass through
http.all('*', () => {
return passthrough()
}),
],
{ scope: 'test' }, // or 'worker'
],
})
test('/product/shoe', async ({ page, msw }) => {
msw.use(
rest.get('http://my-db/product/boot', (req, res, ctx) => {
return res.once(
ctx.status(200),
ctx.json({
title: 'A boot',
})
)
http.get('http://my-db/product/boot', () => {
return HttpResponse.json({
title: 'A boot',
})
})
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment