@@ -5,8 +5,14 @@ const assert = require("node:assert/strict");
55const { CSSStyleDeclaration } = require ( "../lib/CSSStyleDeclaration" ) ;
66
77describe ( "CSSStyleDeclaration" , ( ) => {
8+ const window = {
9+ getComputedStyle : ( ) => { } ,
10+ DOMException : globalThis . DOMException ,
11+ TypeError : globalThis . TypeError
12+ } ;
13+
814 it ( "has methods" , ( ) => {
9- const style = new CSSStyleDeclaration ( ) ;
15+ const style = new CSSStyleDeclaration ( window ) ;
1016 assert . strictEqual ( typeof style . item , "function" ) ;
1117 assert . strictEqual ( typeof style . getPropertyValue , "function" ) ;
1218 assert . strictEqual ( typeof style . setProperty , "function" ) ;
@@ -15,7 +21,7 @@ describe("CSSStyleDeclaration", () => {
1521 } ) ;
1622
1723 it ( "has attributes" , ( ) => {
18- const style = new CSSStyleDeclaration ( ) ;
24+ const style = new CSSStyleDeclaration ( window ) ;
1925 assert . ok ( style . __lookupGetter__ ( "cssText" ) ) ;
2026 assert . ok ( style . __lookupSetter__ ( "cssText" ) ) ;
2127 assert . ok ( style . __lookupGetter__ ( "length" ) ) ;
@@ -24,9 +30,6 @@ describe("CSSStyleDeclaration", () => {
2430 } ) ;
2531
2632 it ( "sets internals for Element" , ( ) => {
27- const window = {
28- DOMException : globalThis . DOMException
29- } ;
3033 const node = {
3134 nodeType : 1 ,
3235 style : { } ,
@@ -47,9 +50,6 @@ describe("CSSStyleDeclaration", () => {
4750 } ) ;
4851
4952 it ( "sets internals for CSSRule" , ( ) => {
50- const window = {
51- DOMException : globalThis . DOMException
52- } ;
5353 const rule = {
5454 parentRule : { } ,
5555 parentStyleSheet : {
@@ -67,7 +67,7 @@ describe("CSSStyleDeclaration", () => {
6767 } ) ;
6868
6969 it ( "has format in internal options" , ( ) => {
70- const style = new CSSStyleDeclaration ( null , {
70+ const style = new CSSStyleDeclaration ( window , {
7171 foo : "bar"
7272 } ) ;
7373 assert . deepEqual ( style . _options , {
@@ -77,7 +77,7 @@ describe("CSSStyleDeclaration", () => {
7777 } ) ;
7878
7979 it ( "should not override format if exists" , ( ) => {
80- const style = new CSSStyleDeclaration ( null , {
80+ const style = new CSSStyleDeclaration ( window , {
8181 format : "computedValue"
8282 } ) ;
8383 assert . deepEqual ( style . _options , {
@@ -86,10 +86,6 @@ describe("CSSStyleDeclaration", () => {
8686 } ) ;
8787
8888 it ( "getting cssText returns empty string if computed flag is set" , ( ) => {
89- const window = {
90- getComputedStyle : ( ) => { } ,
91- DOMException : globalThis . DOMException
92- } ;
9389 const style = new CSSStyleDeclaration ( window , {
9490 format : "computedValue"
9591 } ) ;
@@ -98,79 +94,75 @@ describe("CSSStyleDeclaration", () => {
9894 } ) ;
9995
10096 it ( "setting improper css to cssText should not throw" , ( ) => {
101- const style = new CSSStyleDeclaration ( ) ;
97+ const style = new CSSStyleDeclaration ( window ) ;
10298 style . cssText = "color: " ;
10399 assert . strictEqual ( style . cssText , "" ) ;
104100 style . cssText = "color: red!" ;
105101 assert . strictEqual ( style . cssText , "" ) ;
106102 } ) ;
107103
108104 it ( "item() throws if argument is not given" , ( ) => {
109- const style = new CSSStyleDeclaration ( ) ;
105+ const style = new CSSStyleDeclaration ( window ) ;
110106 assert . throws (
111107 ( ) => {
112108 style . item ( ) ;
113109 } ,
114110 ( e ) => {
115- assert . strictEqual ( e instanceof globalThis . TypeError , true ) ;
111+ assert . strictEqual ( e instanceof window . TypeError , true ) ;
116112 assert . strictEqual ( e . message , "1 argument required, but only 0 present." ) ;
117113 return true ;
118114 }
119115 ) ;
120116 } ) ;
121117
122118 it ( "camelcase properties are not assigned with setproperty()" , ( ) => {
123- const style = new CSSStyleDeclaration ( ) ;
119+ const style = new CSSStyleDeclaration ( window ) ;
124120 style . setProperty ( "fontSize" , "12px" ) ;
125121 assert . strictEqual ( style . cssText , "" ) ;
126122 } ) ;
127123
128124 it ( "custom properties are case-sensitive" , ( ) => {
129- const style = new CSSStyleDeclaration ( ) ;
125+ const style = new CSSStyleDeclaration ( window ) ;
130126 style . cssText = "--fOo: purple" ;
131127
132128 assert . strictEqual ( style . getPropertyValue ( "--foo" ) , "" ) ;
133129 assert . strictEqual ( style . getPropertyValue ( "--fOo" ) , "purple" ) ;
134130 } ) ;
135131
136132 it ( "getPropertyValue for custom properties in cssText" , ( ) => {
137- const style = new CSSStyleDeclaration ( ) ;
133+ const style = new CSSStyleDeclaration ( window ) ;
138134 style . cssText = "--foo: red" ;
139135
140136 assert . strictEqual ( style . getPropertyValue ( "--foo" ) , "red" ) ;
141137 } ) ;
142138
143139 it ( "getPropertyValue for custom properties with setProperty" , ( ) => {
144- const style = new CSSStyleDeclaration ( ) ;
140+ const style = new CSSStyleDeclaration ( window ) ;
145141 style . setProperty ( "--bar" , "blue" ) ;
146142
147143 assert . strictEqual ( style . getPropertyValue ( "--bar" ) , "blue" ) ;
148144 } ) ;
149145
150146 it ( "getPropertyValue for custom properties with object setter" , ( ) => {
151- const style = new CSSStyleDeclaration ( ) ;
147+ const style = new CSSStyleDeclaration ( window ) ;
152148 style [ "--baz" ] = "yellow" ;
153149
154150 assert . strictEqual ( style . getPropertyValue ( "--baz" ) , "" ) ;
155151 } ) ;
156152
157153 it ( "getPropertyPriority for property" , ( ) => {
158- const style = new CSSStyleDeclaration ( ) ;
154+ const style = new CSSStyleDeclaration ( window ) ;
159155 style . setProperty ( "color" , "green" , "important" ) ;
160156 assert . strictEqual ( style . getPropertyPriority ( "color" ) , "important" ) ;
161157 } ) ;
162158
163159 it ( "getPropertyPriority for custom property" , ( ) => {
164- const style = new CSSStyleDeclaration ( ) ;
160+ const style = new CSSStyleDeclaration ( window ) ;
165161 style . setProperty ( "--foo" , "green" , "important" ) ;
166162 assert . strictEqual ( style . getPropertyPriority ( "--foo" ) , "important" ) ;
167163 } ) ;
168164
169165 it ( "setProperty throws if read-only flag is set" , ( ) => {
170- const window = {
171- getComputedStyle : ( ) => { } ,
172- DOMException : globalThis . DOMException
173- } ;
174166 const style = new CSSStyleDeclaration ( window ) ;
175167 style . setProperty ( "--foo" , "green" ) ;
176168 style . setOptions ( {
@@ -190,10 +182,6 @@ describe("CSSStyleDeclaration", () => {
190182 } ) ;
191183
192184 it ( "removeProperty throws if read-only flag is set" , ( ) => {
193- const window = {
194- getComputedStyle : ( ) => { } ,
195- DOMException : globalThis . DOMException
196- } ;
197185 const style = new CSSStyleDeclaration ( window ) ;
198186 style . setProperty ( "--foo" , "green" ) ;
199187 style . setProperty ( "--bar" , "red" ) ;
0 commit comments