@@ -5,9 +5,8 @@ const assert = require("node:assert/strict");
5
5
const { CSSStyleDeclaration } = require ( "../lib/CSSStyleDeclaration" ) ;
6
6
7
7
describe ( "CSSStyleDeclaration" , ( ) => {
8
- it ( "does not enumerate constructor or internals" , ( ) => {
8
+ it ( "does not enumerate internals" , ( ) => {
9
9
const style = new CSSStyleDeclaration ( ) ;
10
- assert . strictEqual ( Object . getOwnPropertyDescriptor ( style , "constructor" ) . enumerable , false ) ;
11
10
for ( const i in style ) {
12
11
assert . strictEqual ( i . startsWith ( "_" ) , false ) ;
13
12
}
@@ -31,69 +30,46 @@ describe("CSSStyleDeclaration", () => {
31
30
assert . ok ( style . __lookupGetter__ ( "parentRule" ) ) ;
32
31
} ) ;
33
32
34
- it ( "sets internals for Window " , ( ) => {
33
+ it ( "sets internals for Element " , ( ) => {
35
34
const window = {
36
- getComputedStyle : ( ) => { } ,
37
35
DOMException : globalThis . DOMException
38
36
} ;
39
- const style = new CSSStyleDeclaration ( window ) ;
40
- assert . throws (
41
- ( ) => {
42
- style . cssText = "color: green;" ;
43
- } ,
44
- ( e ) => {
45
- assert . strictEqual ( e instanceof window . DOMException , true ) ;
46
- assert . strictEqual ( e . name , "NoModificationAllowedError" ) ;
47
- assert . strictEqual ( e . message , "cssText can not be modified." ) ;
48
- return true ;
49
- }
50
- ) ;
51
- assert . throws (
52
- ( ) => {
53
- style . removeProperty ( "color" ) ;
54
- } ,
55
- ( e ) => {
56
- assert . strictEqual ( e instanceof window . DOMException , true ) ;
57
- assert . strictEqual ( e . name , "NoModificationAllowedError" ) ;
58
- assert . strictEqual ( e . message , "Property color can not be modified." ) ;
59
- return true ;
60
- }
61
- ) ;
62
- } ) ;
63
-
64
- it ( "sets internals for Element" , ( ) => {
65
37
const node = {
66
38
nodeType : 1 ,
67
39
style : { } ,
68
40
ownerDocument : {
69
- defaultView : {
70
- DOMException : globalThis . DOMException
71
- }
41
+ defaultView : window
72
42
}
73
43
} ;
74
44
let callCount = 0 ;
75
45
const callback = ( ) => {
76
46
callCount ++ ;
77
47
} ;
78
- const style = new CSSStyleDeclaration ( node , {
48
+ const style = new CSSStyleDeclaration ( window , {
49
+ context : node ,
79
50
onChange : callback
80
51
} ) ;
81
52
style . cssText = "color: green;" ;
82
53
assert . strictEqual ( callCount , 1 ) ;
83
54
} ) ;
84
55
85
56
it ( "sets internals for CSSRule" , ( ) => {
57
+ const window = {
58
+ DOMException : globalThis . DOMException
59
+ } ;
86
60
const rule = {
87
61
parentRule : { } ,
88
62
parentStyleSheet : {
89
63
ownerDocument : {
90
64
defaultView : {
91
- DOMException : globalThis . DOMException
65
+ DOMException : window . DOMException
92
66
}
93
67
}
94
68
}
95
69
} ;
96
- const style = new CSSStyleDeclaration ( rule ) ;
70
+ const style = new CSSStyleDeclaration ( window , {
71
+ context : rule
72
+ } ) ;
97
73
assert . deepEqual ( style . parentRule , rule ) ;
98
74
} ) ;
99
75
@@ -116,35 +92,19 @@ describe("CSSStyleDeclaration", () => {
116
92
} ) ;
117
93
} ) ;
118
94
119
- it ( "getting cssText() returns empty string if computedflag is set" , ( ) => {
95
+ it ( "getting cssText returns empty string if computedflag is set" , ( ) => {
120
96
const window = {
121
97
getComputedStyle : ( ) => { } ,
122
98
DOMException : globalThis . DOMException
123
99
} ;
124
- const style = new CSSStyleDeclaration ( window ) ;
100
+ const style = new CSSStyleDeclaration ( window , {
101
+ format : "computedValue"
102
+ } ) ;
103
+ style . cssText = "color: red;" ;
125
104
assert . strictEqual ( style . cssText , "" ) ;
126
105
} ) ;
127
106
128
- it ( "setting cssText() throws if readonly flag is set" , ( ) => {
129
- const window = {
130
- getComputedStyle : ( ) => { } ,
131
- DOMException : globalThis . DOMException
132
- } ;
133
- const style = new CSSStyleDeclaration ( window ) ;
134
- assert . throws (
135
- ( ) => {
136
- style . cssText = "color: green;" ;
137
- } ,
138
- ( e ) => {
139
- assert . strictEqual ( e instanceof window . DOMException , true ) ;
140
- assert . strictEqual ( e . name , "NoModificationAllowedError" ) ;
141
- assert . strictEqual ( e . message , "cssText can not be modified." ) ;
142
- return true ;
143
- }
144
- ) ;
145
- } ) ;
146
-
147
- it ( "setting improper css to csstext should not throw" , ( ) => {
107
+ it ( "setting improper css to cssText should not throw" , ( ) => {
148
108
const style = new CSSStyleDeclaration ( ) ;
149
109
style . cssText = "color: " ;
150
110
assert . strictEqual ( style . cssText , "" ) ;
@@ -200,4 +160,41 @@ describe("CSSStyleDeclaration", () => {
200
160
201
161
assert . strictEqual ( style . getPropertyValue ( "--baz" ) , "" ) ;
202
162
} ) ;
163
+
164
+ it ( "getPropertyPriority for property" , ( ) => {
165
+ const style = new CSSStyleDeclaration ( ) ;
166
+ style . setProperty ( "color" , "green" , "important" ) ;
167
+ assert . strictEqual ( style . getPropertyPriority ( "color" ) , "important" ) ;
168
+ } ) ;
169
+
170
+ it ( "getPropertyPriority for custom property" , ( ) => {
171
+ const style = new CSSStyleDeclaration ( ) ;
172
+ style . setProperty ( "--foo" , "green" , "important" ) ;
173
+ assert . strictEqual ( style . getPropertyPriority ( "--foo" ) , "important" ) ;
174
+ } ) ;
175
+
176
+ it ( "removeProperty throws if readonly flag is set" , ( ) => {
177
+ const window = {
178
+ getComputedStyle : ( ) => { } ,
179
+ DOMException : globalThis . DOMException
180
+ } ;
181
+ const style = new CSSStyleDeclaration ( window ) ;
182
+ assert . strictEqual ( style . readOnly , false ) ;
183
+ style . setProperty ( "--foo" , "green" ) ;
184
+ style . setProperty ( "--bar" , "red" ) ;
185
+ assert . strictEqual ( style . removeProperty ( "--foo" ) , "green" ) ;
186
+ style . readOnly = true ;
187
+ assert . strictEqual ( style . readOnly , true ) ;
188
+ assert . throws (
189
+ ( ) => {
190
+ style . removeProperty ( "--bar" ) ;
191
+ } ,
192
+ ( e ) => {
193
+ assert . strictEqual ( e instanceof window . DOMException , true ) ;
194
+ assert . strictEqual ( e . name , "NoModificationAllowedError" ) ;
195
+ assert . strictEqual ( e . message , "Property --bar can not be modified." ) ;
196
+ return true ;
197
+ }
198
+ ) ;
199
+ } ) ;
203
200
} ) ;
0 commit comments