Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

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

Max Schmitt421872f13084
diff --git a/tests/page/page-request-fulfill.spec.ts b/tests/page/page-request-fulfill.spec.ts
index 02c705c518..376b03d69c 100644
--- a/tests/page/page-request-fulfill.spec.ts
+++ b/tests/page/page-request-fulfill.spec.ts
@@ -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' }));
});