@@ -2,6 +2,56 @@ import StyleObserver from "../index.js";
2
2
import gentleRegisterProperty from "./util/gentle-register-property.js" ;
3
3
import tests from "./tests.js" ;
4
4
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
+
5
55
export default {
6
56
name : "Shadow DOM" ,
7
57
@@ -14,7 +64,7 @@ export default {
14
64
15
65
run ( { property, meta, initial, value} ) {
16
66
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 ) ;
18
68
let target = host . shadowRoot . getElementById ( id ) ;
19
69
20
70
if ( property . startsWith ( "--" ) ) {
@@ -70,14 +120,20 @@ export default {
70
120
data : {
71
121
hostId : "imperative-host" ,
72
122
} ,
73
- tests,
123
+ tests : [
124
+ ...tests ,
125
+ inlineStyleTest ,
126
+ ] ,
74
127
} ,
75
128
{
76
129
name : "Declarative" ,
77
130
data : {
78
131
hostId : "declarative-host" ,
79
132
} ,
80
- tests,
133
+ tests : [
134
+ ...tests ,
135
+ inlineStyleTest ,
136
+ ] ,
81
137
} ,
82
138
{
83
139
name : "Registered custom element" ,
@@ -98,7 +154,10 @@ export default {
98
154
data : {
99
155
hostId : "registered-host" ,
100
156
} ,
101
- tests,
157
+ tests : [
158
+ ...tests ,
159
+ inlineStyleTest ,
160
+ ] ,
102
161
} ,
103
162
] ,
104
163
} ;
0 commit comments