@@ -148,14 +148,10 @@ export class ElementAssertion<T extends Element> extends Assertion<T> {
148148 }
149149
150150 public toHaveStyle ( css : Object | string ) : this {
151- const styleTest = document . createElement ( "div" ) ;
152- styleTest . style . color = "red" ;
153- styleTest . style . display = "flex" ;
154151 if (
155152 this . actual instanceof HTMLElement ||
156153 this . actual [ 'ownerDocument' ]
157154 ) {
158-
159155
160156 const parsedCSS = typeof css === 'object'
161157 ? css
@@ -166,8 +162,8 @@ export class ElementAssertion<T extends Element> extends Assertion<T> {
166162 const computedStyle = window ?. getComputedStyle ;
167163
168164 const expected = parsedCSS
165+ console . log ( "expected: " , expected ) ;
169166 const received = computedStyle ?.( this . actual ) ;
170- const expectedRule = expected . rules [ 0 ] ;
171167
172168 interface StyleDeclaration {
173169 property : string ;
@@ -181,7 +177,23 @@ export class ElementAssertion<T extends Element> extends Assertion<T> {
181177 const normalizer = document . createElement ( "div" ) ;
182178 document . body . appendChild ( normalizer ) ;
183179
180+ if ( typeof css === 'object' ) {
181+ Object . entries ( css ) . map ( ( [ property , value ] ) => {
182+ props = [ ...props , property ] ;
183+
184+ normalizer . style [ property ] = value ;
185+ const normalizedValue = window ?. getComputedStyle ( normalizer ) . getPropertyValue ( property ) ;
186+
187+ expectedStyle = {
188+ ...expectedStyle ,
189+ [ property ] : normalizedValue ?. trim ( ) ,
184190
191+ } ;
192+
193+ } ) ;
194+ console . log ( "EXPECTED STYLE: " , expectedStyle ) ;
195+ } else {
196+ const expectedRule = expected . rules [ 0 ] ;
185197 expectedRule . declarations . map ( ( declaration : StyleDeclaration ) => {
186198 const property = declaration . property ;
187199 const value = declaration . value ;
@@ -198,6 +210,7 @@ export class ElementAssertion<T extends Element> extends Assertion<T> {
198210
199211 return expectedStyle ;
200212 } ) ;
213+ }
201214
202215 document . body . removeChild ( normalizer ) ;
203216
0 commit comments