Skip to content

Commit 7e223f0

Browse files
committed
test: add GET form method test case
1 parent 205f2c9 commit 7e223f0

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

test/browser/rest-api/navigate.test.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ declare namespace window {
1515
1616
Request shapes (the x-axis)
1717
18-
3. <form method="GET"> submit via requestSubmit() — query string encoding
19-
4. <form method="POST"> with application/x-www-form-urlencoded body
20-
5. <form method="POST" enctype="multipart/form-data"> with a file field
2118
6. Nested navigation — <iframe> src or form inside iframe (mode: "nested-navigate" in spec)
2219
*/
2320

@@ -303,3 +300,32 @@ test('responds to a form submission with a mocked 4xx response', async ({
303300
await page.getByRole('button', { name: 'Submit' }).click()
304301
await expect(page.getByRole('heading')).toHaveText('Unauthorized')
305302
})
303+
304+
test('intercepts a form submission with a "GET" method', async ({
305+
loadExample,
306+
page,
307+
}) => {
308+
await loadExample(new URL('./navigate.mocks.ts', import.meta.url))
309+
310+
await page.evaluate(() => {
311+
const { worker, http, HttpResponse } = window.msw
312+
313+
worker.use(
314+
http.get('/action', ({ request }) => {
315+
const url = new URL(request.url)
316+
const username = url.searchParams.get('username')
317+
return HttpResponse.html(`<h1>Hello, ${username}!</h1>`)
318+
}),
319+
)
320+
321+
document.querySelector('form')!.setAttribute('method', 'GET')
322+
})
323+
324+
await page.getByLabel('Username').fill('octocat')
325+
await page.getByRole('button', { name: 'Submit' }).click()
326+
327+
await expect(page).toHaveURL(
328+
new URL('/action?username=octocat', page.url()).href,
329+
)
330+
await expect(page.getByRole('heading')).toHaveText('Hello, octocat!')
331+
})

0 commit comments

Comments
 (0)