test: rewrite 'should fulfill json' test (#23735)

This commit is contained in:
Max Schmitt 2023-06-15 18:46:19 +02:00 committed by GitHub
parent 8602981d87
commit 421872f130
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -379,7 +379,8 @@ it('should fulfill preload link requests', async ({ page, server, browserName })
});
it('should fulfill json', async ({ page, server }) => {
await page.route('**/*', route => {
await page.goto(server.EMPTY_PAGE);
await page.route('**/data.json', route => {
void route.fulfill({
status: 201,
headers: {
@ -388,8 +389,11 @@ it('should fulfill json', async ({ page, server }) => {
json: { bar: 'baz' },
});
});
const response = await page.goto(server.EMPTY_PAGE);
const [response, body] = await Promise.all([
page.waitForResponse('**/*'),
page.evaluate(() => fetch('./data.json').then(r => r.text()))
]);
expect(response.status()).toBe(201);
expect(response.headers()['content-type']).toBe('application/json');
expect(await page.evaluate(() => document.body.textContent)).toBe(JSON.stringify({ bar: 'baz' }));
expect(body).toBe(JSON.stringify({ bar: 'baz' }));
});