From 6e273469672b9a92e18adc3455e7a70d09bc35b9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFs=20Poujade?= <lois.poujade@tetras-libre.fr>
Date: Mon, 28 Nov 2022 15:50:56 +0100
Subject: [PATCH] Add wait/HTTP status check

---
 __tests__/main.js | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/__tests__/main.js b/__tests__/main.js
index c5d2cd9..ca4809d 100644
--- a/__tests__/main.js
+++ b/__tests__/main.js
@@ -1,12 +1,14 @@
 describe('Open example', () => {
   beforeAll(async () => {
     await page.goto('https://example.org');
+    expect(page.status()).toBe(200);
   });
   it('has the correct page title', async () => {
     const title = await page.title();
     expect(title).toBe('Example Domain');
   });
   it('has the main text', async () => {
+    await page.waitForSelector('a[href="https://www.iana.org/domains/example"]');
     await expect(page).toMatchElement('a[href="https://www.iana.org/domains/example"]');
   });
 });
@@ -14,12 +16,14 @@ describe('Open example', () => {
 describe('Open local HTTP server', () => {
   beforeAll(async () => {
     await page.goto('http://127.0.0.1:4488');
+    expect(page.status()).toBe(200);
   });
   it('has the correct page title', async () => {
     const title = await page.title();
     expect(title).toBe('Index of /');
   });
   it('has the correct link', async () => {
+    await page.waitForSelector('a[href="./jest.json"]');
     await expect(page).toMatchElement('a[href="./jest.json"]');
   });
 });
@@ -27,12 +31,14 @@ describe('Open local HTTP server', () => {
 describe('Open example', () => {
   beforeAll(async () => {
     await page.goto('https://example.org');
+    expect(page.status()).toBe(200);
   });
   it('has the correct page title', async () => {
     const title = await page.title();
     expect(title).toBe('Example Domain');
   });
   it('has the main text', async () => {
+    await page.waitForSelector('a[href="https://www.iana.org/domains/example"]');
     await expect(page).toMatchElement('a[href="https://www.iana.org/domains/example"]');
   });
 });
@@ -40,12 +46,14 @@ describe('Open example', () => {
 describe('Open local HTTP server', () => {
   beforeAll(async () => {
     await page.goto('http://127.0.0.1:4488');
+    expect(page.status()).toBe(200);
   });
   it('has the correct page title', async () => {
     const title = await page.title();
     expect(title).toBe('Index of /');
   });
   it('has the correct link', async () => {
+    await page.waitForSelector('a[href="./jest.json"]');
     await expect(page).toMatchElement('a[href="./jest.json"]');
   });
 });
-- 
GitLab