@@ -368,4 +368,47 @@ describe("[Unit] ElementAssertion.test.ts", () => {
368368 } ) ;
369369 } ) ;
370370 } ) ;
371+
372+ describe ( ".toHaveSomeStyle" , ( ) => {
373+ context ( "when the element contains one or more expected styles" , ( ) => {
374+ it ( "returns the assertion instance" , ( ) => {
375+ const { getByTestId } = render (
376+ < div
377+ style = { { color : "blue" , maxHeight : "3rem" , width : "2rem" } }
378+ data-testid = "test-div"
379+ /> ,
380+ ) ;
381+ const divTest = getByTestId ( "test-div" ) ;
382+ const test = new ElementAssertion ( divTest ) ;
383+
384+ expect ( test . toHaveSomeStyle ( { color : "red" , display : "flex" , height : "3rem" , width : "2rem" } ) ) . toBeEqual ( test ) ;
385+
386+ expect ( ( ) => test . not . toHaveSomeStyle ( { color : "blue" } ) )
387+ . toThrowError ( AssertionError )
388+ // eslint-disable-next-line max-len
389+ . toHaveMessage ( "Expected the element NOT to match some of the following styles:\n{\n \"color\": \"rgb(0, 0, 255)\"\n}" ) ;
390+ } ) ;
391+ } ) ;
392+
393+ context ( "when the element does not contain any of the expected styles" , ( ) => {
394+ it ( "throws an assertion error" , ( ) => {
395+ const { getByTestId } = render (
396+ < div
397+ className = "foo bar test"
398+ style = { { border : "1px solid black" , color : "blue" , display : "block" } }
399+ data-testid = "test-div"
400+ /> ,
401+ ) ;
402+ const divTest = getByTestId ( "test-div" ) ;
403+ const test = new ElementAssertion ( divTest ) ;
404+
405+ expect ( ( ) => test . toHaveSomeStyle ( { color : "red" , display : "flex" } ) )
406+ . toThrowError ( AssertionError )
407+ // eslint-disable-next-line max-len
408+ . toHaveMessage ( "Expected the element to match some of the following styles:\n{\n \"color\": \"rgb(255, 0, 0)\",\n \"display\": \"flex\"\n}" ) ;
409+
410+ expect ( test . not . toHaveSomeStyle ( { border : "1px solid blue" , color : "red" , display : "flex" } ) ) . toBeEqual ( test ) ;
411+ } ) ;
412+ } ) ;
413+ } ) ;
371414} ) ;
0 commit comments