test: add test for sendBeacon and asserting request body (#12274)

This commit is contained in:
Max Schmitt 2022-02-22 20:15:24 +01:00 committed by GitHub
parent 17a922cf5e
commit be2e4866b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -107,3 +107,17 @@ it('should get post data for file/blob', async ({ page, server, browserName }) =
]);
expect(request.postData()).toBe('file-contents');
});
it('should get post data for navigator.sendBeacon api calls', async ({ page, server, browserName }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/12231' });
it.fail(browserName === 'chromium', 'postData is empty');
it.fail(browserName === 'webkit', 'postData is empty');
await page.goto(server.EMPTY_PAGE);
const [request] = await Promise.all([
page.waitForRequest('**/*'),
page.evaluate(() => navigator.sendBeacon(window.location.origin + '/api/foo', new Blob([JSON.stringify({ foo: 'bar' })])))
]);
expect(request.method()).toBe('POST');
expect(request.url()).toBe(server.PREFIX + '/api/foo');
expect(request.postDataJSON()).toStrictEqual({ foo: 'bar' });
});