Skip to content

Commit

Permalink
test: postBody for intercepted fetch FormData with Blob
Browse files Browse the repository at this point in the history
Fixes #24077
  • Loading branch information
yury-s committed Jun 14, 2024
1 parent 4fff548 commit 674cc30
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/page/page-request-intercept.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,39 @@ it('should fulfill popup main request using alias', async ({ page, server, isEle
]);
await expect(popup.locator('body')).toHaveText('hello');
});

it('request.postData is not null when fetching FormData with a Blob', {
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/24077' }
}, async ({ server, page, browserName, isElectron }) => {
it.fixme(isElectron, 'error: Browser context management is not supported.');
it.fixme(browserName === 'webkit', 'The body is empty in WebKit when intercepting');
await page.goto(server.EMPTY_PAGE);
await page.setContent(`
<script>
function doStuff() {
const formData = new FormData();
formData.append('file', new Blob(["hello"], { type: "text/plain" }));
fetch('/upload', {
method: 'POST',
body: formData
});
}
</script>
<body>
<button onclick="doStuff()" data-testid="click-me">Click me!</button>
</body>`);
let resolvePostData;
const postDataPromise = new Promise<string>(resolve => resolvePostData = resolve);
await page.route(server.PREFIX + '/upload', async (route, request) => {
expect(request.method()).toBe('POST');
resolvePostData(await request.postData());
route.fulfill({

Check failure on line 310 in tests/page/page-request-intercept.spec.ts

View workflow job for this annotation

GitHub Actions / docs & lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
status: 200,
body: 'ok',
});
});
await page.getByTestId('click-me').click();
const postData = await postDataPromise;
expect(postData).toContain('Content-Disposition: form-data; name="file"; filename="blob"');
expect(postData).toContain('\r\nhello\r\n');
});

0 comments on commit 674cc30

Please sign in to comment.