blob: 3355e94dd8cfad815f4d11f62a42eaeaae9d9726 (
plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
import { beforeEach, describe, expect, test } from "vitest";
import { setupDOM } from "./utils.js";
// built via npm script "build:test:02"
import { main } from "@root/examples/02-interactivity/build/dev/javascript/app/app.mjs";
let appEl;
beforeEach(() => {
setupDOM();
appEl = document.getElementById("app");
});
describe("counter example", () => {
test("should render initially", () => {
main();
expect(document.toString()).toMatchSnapshot();
});
test("should increment on button press", () => {
main();
const buttons = document.querySelectorAll("button.lustre-ui-button");
const incrementButton = buttons[0];
const count = document.querySelector("p");
expect(incrementButton).toBeTruthy();
incrementButton.click();
expect(count.innerText).toBe("1");
incrementButton.click();
expect(count.innerText).toBe("2");
incrementButton.click();
expect(count.innerText).toBe("3");
});
test("should decrement on button press", () => {
main();
const buttons = document.querySelectorAll("button.lustre-ui-button");
const decrementButton = buttons[1];
const count = document.querySelector("p");
expect(decrementButton).toBeTruthy();
decrementButton.click();
expect(count.innerText).toBe("-1");
decrementButton.click();
expect(count.innerText).toBe("-2");
decrementButton.click();
expect(count.innerText).toBe("-3");
});
test("should increment and decrement on button press", () => {
main();
const buttons = document.querySelectorAll("button.lustre-ui-button");
const incrementButton = buttons[0];
const decrementButton = buttons[1];
const count = document.querySelector("p");
incrementButton.click();
expect(count.innerText).toBe("1");
incrementButton.click();
expect(count.innerText).toBe("2");
incrementButton.click();
expect(count.innerText).toBe("3");
expect(decrementButton).toBeTruthy();
decrementButton.click();
expect(count.innerText).toBe("2");
decrementButton.click();
expect(count.innerText).toBe("1");
decrementButton.click();
expect(count.innerText).toBe("0");
});
});
|