@@ -5,9 +5,8 @@ const assert = require("node:assert/strict");
55const  {  CSSStyleDeclaration }  =  require ( "../lib/CSSStyleDeclaration" ) ; 
66
77describe ( "CSSStyleDeclaration" ,  ( )  =>  { 
8-   it ( "does not enumerate constructor or  internals" ,  ( )  =>  { 
8+   it ( "does not enumerate internals" ,  ( )  =>  { 
99    const  style  =  new  CSSStyleDeclaration ( ) ; 
10-     assert . strictEqual ( Object . getOwnPropertyDescriptor ( style ,  "constructor" ) . enumerable ,  false ) ; 
1110    for  ( const  i  in  style )  { 
1211      assert . strictEqual ( i . startsWith ( "_" ) ,  false ) ; 
1312    } 
@@ -31,69 +30,46 @@ describe("CSSStyleDeclaration", () => {
3130    assert . ok ( style . __lookupGetter__ ( "parentRule" ) ) ; 
3231  } ) ; 
3332
34-   it ( "sets internals for Window " ,  ( )  =>  { 
33+   it ( "sets internals for Element " ,  ( )  =>  { 
3534    const  window  =  { 
36-       getComputedStyle : ( )  =>  { } , 
3735      DOMException : globalThis . DOMException 
3836    } ; 
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" ,  ( )  =>  { 
6537    const  node  =  { 
6638      nodeType : 1 , 
6739      style : { } , 
6840      ownerDocument : { 
69-         defaultView : { 
70-           DOMException : globalThis . DOMException 
71-         } 
41+         defaultView : window 
7242      } 
7343    } ; 
7444    let  callCount  =  0 ; 
7545    const  callback  =  ( )  =>  { 
7646      callCount ++ ; 
7747    } ; 
78-     const  style  =  new  CSSStyleDeclaration ( node ,  { 
48+     const  style  =  new  CSSStyleDeclaration ( window ,  { 
49+       context : node , 
7950      onChange : callback 
8051    } ) ; 
8152    style . cssText  =  "color: green;" ; 
8253    assert . strictEqual ( callCount ,  1 ) ; 
8354  } ) ; 
8455
8556  it ( "sets internals for CSSRule" ,  ( )  =>  { 
57+     const  window  =  { 
58+       DOMException : globalThis . DOMException 
59+     } ; 
8660    const  rule  =  { 
8761      parentRule : { } , 
8862      parentStyleSheet : { 
8963        ownerDocument : { 
9064          defaultView : { 
91-             DOMException : globalThis . DOMException 
65+             DOMException : window . DOMException 
9266          } 
9367        } 
9468      } 
9569    } ; 
96-     const  style  =  new  CSSStyleDeclaration ( rule ) ; 
70+     const  style  =  new  CSSStyleDeclaration ( window ,  { 
71+       context : rule 
72+     } ) ; 
9773    assert . deepEqual ( style . parentRule ,  rule ) ; 
9874  } ) ; 
9975
@@ -116,35 +92,19 @@ describe("CSSStyleDeclaration", () => {
11692    } ) ; 
11793  } ) ; 
11894
119-   it ( "getting cssText()  returns empty string if computedflag is set" ,  ( )  =>  { 
95+   it ( "getting cssText returns empty string if computedflag is set" ,  ( )  =>  { 
12096    const  window  =  { 
12197      getComputedStyle : ( )  =>  { } , 
12298      DOMException : globalThis . DOMException 
12399    } ; 
124-     const  style  =  new  CSSStyleDeclaration ( window ) ; 
100+     const  style  =  new  CSSStyleDeclaration ( window ,  { 
101+       format : "computedValue" 
102+     } ) ; 
103+     style . cssText  =  "color: red;" ; 
125104    assert . strictEqual ( style . cssText ,  "" ) ; 
126105  } ) ; 
127106
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" ,  ( )  =>  { 
148108    const  style  =  new  CSSStyleDeclaration ( ) ; 
149109    style . cssText  =  "color: " ; 
150110    assert . strictEqual ( style . cssText ,  "" ) ; 
@@ -200,4 +160,41 @@ describe("CSSStyleDeclaration", () => {
200160
201161    assert . strictEqual ( style . getPropertyValue ( "--baz" ) ,  "" ) ; 
202162  } ) ; 
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+   } ) ; 
203200} ) ; 
0 commit comments