forked from QwikDev/qwik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe2e.use-id.spec.ts
48 lines (41 loc) · 1.49 KB
/
e2e.use-id.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { test, expect, Locator } from "@playwright/test";
test.describe("use-id", () => {
test.beforeEach(async ({ page }) => {
await page.goto("/e2e/use-id");
page.on("pageerror", (err) => expect(err).toEqual(undefined));
page.on("console", (msg) => {
if (msg.type() === "error") {
expect(msg.text()).toEqual(undefined);
}
});
// await page.waitForLoadState('networkidle');
await page.waitForTimeout(500); // Wait for useVisibleTask$
});
test("Creates unique ids and ensure no collisions", async ({ page }) => {
const totalIdsLocator = page.locator("#totalIds");
await totalIdsLocator.isVisible();
const totalIdsText = await totalIdsLocator.textContent();
const totalIds = parseInt(totalIdsText || "-1");
await expect(totalIds).toBeGreaterThan(0); // MAKE SURE WE HAVE SOME IDS
const validIdsLocator = page.locator("#validIds");
const validIdsText = await validIdsLocator.textContent();
const validIds = parseInt(validIdsText || "-1");
const collisionsLocator = page.locator("#collisions");
const collisionsText = await collisionsLocator.textContent();
const collisions = parseInt(collisionsText || "-1");
//
// COMPARE VALUES AS AN OBJECT TO SHOW THE ACTUAL RESULTS IN THE TEST REPORT
//
const actual = {
collisions,
totalIds,
validIds,
};
const expected = {
collisions: 0,
totalIds,
validIds,
};
await expect(actual).toMatchObject(expected);
});
});