-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlit.cy.ts
115 lines (96 loc) · 3.33 KB
/
lit.cy.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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import "../../templates/index.css";
import { html } from "lit";
import { LitCounter } from "../../templates/counter-lit";
describe("Lit mount", () => {
it("mounts", () => {
cy.mount<"counter-lit">(html`<counter-lit></counter-lit>`);
cy.get("counter-lit").shadow().contains("h1", "Count is 0");
});
it("reacts to state changes", () => {
cy.mount<"counter-lit">(html`<counter-lit></counter-lit>`);
cy.get("counter-lit").shadow().as("shadow");
cy.get("@shadow").contains("h1", "Count is 0");
cy.get("@shadow").find("button").click();
cy.get("@shadow").contains("h1", "Count is 1");
});
it("accepts props", () => {
cy.mount<"counter-lit">(html`<counter-lit .count=${42}></counter-lit>`);
cy.get("counter-lit").shadow().as("shadow");
cy.get("@shadow").contains("h1", "Count is 42");
});
it("can pass emitters as spies", () => {
cy.mount<"counter-lit">(
html`<counter-lit
.count=${42}
.clicked=${cy.spy().as("onClickedSpy")}
></counter-lit>`,
);
cy.get("counter-lit").shadow().as("shadow");
cy.get("@shadow").contains("h1", "Count is 42");
cy.get("@shadow").find("button").click();
cy.get("@onClickedSpy").should("have.been.calledWith", 42);
});
describe("slotting", () => {
it("can slot HTMLElements", () => {
cy.mount<"counter-lit">(
html`<counter-lit .count=${42} .clicked=${cy.spy().as("onClickedSpy")}>
<div class="div-slotted">
<p>Rendered</p>
</div>
</counter-lit>`,
);
cy.get("counter-lit").shadow().as("shadow");
cy.get("@shadow").get(".div-slotted").find("p").contains("Rendered");
});
it("can slot other web components", () => {
cy.mount<"counter-lit">(
html`<counter-lit .count=${42} .clicked=${cy.spy().as("onClickedSpy")}>
<counter-lit .count=${99}></counter-lit>
</counter-lit>`,
);
cy.get("counter-lit").shadow().as("shadow");
cy.get("@shadow").contains("h1", "Count is 42");
cy.get("@shadow")
.get("counter-lit")
.shadow()
.contains("h1", "Count is 99");
});
});
describe("wrapping", () => {
it("component is instance of web component", () => {
cy.mount<"counter-lit">(html`<counter-lit></counter-lit>`).then(
(component) => {
expect(component[0]).to.be.instanceOf(LitCounter);
},
);
});
});
context("log", () => {
it("displays component name in mount log", () => {
cy.mount<"counter-lit">(html`<counter-lit .count=${42}></counter-lit>`);
cy.wrap(Cypress.$(window.top.document.body)).within(() =>
cy
.contains("displays component name in mount log")
.closest(".collapsible")
.click()
.within(() =>
cy
.get(".command-name-mount")
.should("contain", "mount<counter-lit ... />"),
),
);
});
it("does not display mount log", () => {
cy.mount<"counter-lit">(html`<counter-lit .count=${42}></counter-lit>`, {
log: false,
});
cy.wrap(Cypress.$(window.top.document.body)).within(() =>
cy
.contains("does not display mount log")
.closest(".collapsible")
.click()
.within(() => cy.get(".command-name-mount").should("not.exist")),
);
});
});
});