Skip to content

Commit 55601b4

Browse files
DmitrySharabinLeaVerou
authored andcommitted
Add tests (#112)
1 parent c117b68 commit 55601b4

File tree

1 file changed

+63
-4
lines changed

1 file changed

+63
-4
lines changed

tests/shadow.js

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,56 @@ import StyleObserver from "../index.js";
22
import gentleRegisterProperty from "./util/gentle-register-property.js";
33
import tests from "./tests.js";
44

5+
const inlineStyleTest = {
6+
name: "Don't use inline styles",
7+
async run ({property, meta, initial, value}) {
8+
// Make the property unique
9+
property += "-" + this.data.hostId;
10+
11+
let host = document.getElementById(this.data.hostId);
12+
host.style.setProperty(property, initial);
13+
14+
return new Promise((resolve, reject) => {
15+
let observer = new StyleObserver(records => {
16+
resolve("Observer fired");
17+
});
18+
19+
observer.observe(host, property);
20+
21+
requestAnimationFrame(() => {
22+
host.style.setProperty(property, value);
23+
});
24+
25+
// Timeout after 500ms
26+
setTimeout(() => reject(), 500);
27+
})
28+
.catch(_ => "Observer did not fire")
29+
.then(result => {
30+
let inlineValue = host.style.getPropertyValue("--style-observer-transition");
31+
let adoptedValue = getComputedStyle(host).getPropertyValue("--style-observer-transition");
32+
33+
return { result, inlineValue, adoptedValue };
34+
});
35+
},
36+
map (value) {
37+
let { result, inlineValue, adoptedValue } = value;
38+
inlineValue = inlineValue.length === 0 || inlineValue === "Empty";
39+
adoptedValue = adoptedValue.length > 0;
40+
41+
return { result, inlineValue, adoptedValue };
42+
},
43+
arg: {
44+
property: "--test-inline-style",
45+
initial: "foo",
46+
value: "bar",
47+
},
48+
expect: {
49+
result: "Observer fired",
50+
inlineValue: "Empty",
51+
adoptedValue: "Not empty",
52+
},
53+
};
54+
555
export default {
656
name: "Shadow DOM",
757

@@ -14,7 +64,7 @@ export default {
1464

1565
run ({property, meta, initial, value}) {
1666
let host = document.getElementById(this.data.hostId);
17-
let id = this.arg.property + "-" + CSS.escape(this.arg.value);
67+
let id = property + "-" + CSS.escape(value);
1868
let target = host.shadowRoot.getElementById(id);
1969

2070
if (property.startsWith("--")) {
@@ -70,14 +120,20 @@ export default {
70120
data: {
71121
hostId: "imperative-host",
72122
},
73-
tests,
123+
tests: [
124+
...tests,
125+
inlineStyleTest,
126+
],
74127
},
75128
{
76129
name: "Declarative",
77130
data: {
78131
hostId: "declarative-host",
79132
},
80-
tests,
133+
tests: [
134+
...tests,
135+
inlineStyleTest,
136+
],
81137
},
82138
{
83139
name: "Registered custom element",
@@ -98,7 +154,10 @@ export default {
98154
data: {
99155
hostId: "registered-host",
100156
},
101-
tests,
157+
tests: [
158+
...tests,
159+
inlineStyleTest,
160+
],
102161
},
103162
],
104163
};

0 commit comments

Comments
 (0)