@@ -15,6 +15,7 @@ describe('.toHaveStyle', () => {
1515 background-color: black;
1616 color: white;
1717 float: left;
18+ transition: opacity 0.2s ease-out, top 0.3s cubic-bezier(1.175, 0.885, 0.32, 1.275);
1819 }
1920 `
2021 document . body . appendChild ( style )
@@ -30,6 +31,11 @@ describe('.toHaveStyle', () => {
3031 background-color: blue;
3132 color: white;
3233 ` )
34+
35+ expect ( container . querySelector ( '.label' ) ) . toHaveStyle (
36+ 'transition: opacity 0.2s ease-out, top 0.3s cubic-bezier(1.175, 0.885, 0.32, 1.275)' ,
37+ )
38+
3339 expect ( container . querySelector ( '.label' ) ) . toHaveStyle (
3440 'background-color:blue;color:white' ,
3541 )
@@ -53,6 +59,7 @@ describe('.toHaveStyle', () => {
5359 background-color: black;
5460 color: white;
5561 float: left;
62+ transition: opacity 0.2s ease-out, top 0.3s cubic-bezier(1.175, 0.885, 0.32, 1.275);
5663 }
5764 `
5865 document . body . appendChild ( style )
@@ -63,16 +70,24 @@ describe('.toHaveStyle', () => {
6370 'font-weight: bold' ,
6471 ) ,
6572 ) . toThrowError ( )
73+
6674 expect ( ( ) =>
6775 expect ( container . querySelector ( '.label' ) ) . not . toHaveStyle ( 'color: white' ) ,
6876 ) . toThrowError ( )
6977
78+ expect ( ( ) =>
79+ expect ( container . querySelector ( '.label' ) ) . toHaveStyle (
80+ 'transition: all 0.7s ease, width 1.0s cubic-bezier(3, 4, 5, 6);' ,
81+ ) ,
82+ ) . toThrowError ( )
83+
7084 // Make sure the test fails if the css syntax is not valid
7185 expect ( ( ) =>
7286 expect ( container . querySelector ( '.label' ) ) . not . toHaveStyle (
7387 'font-weight bold' ,
7488 ) ,
7589 ) . toThrowError ( )
90+
7691 expect ( ( ) =>
7792 expect ( container . querySelector ( '.label' ) ) . toHaveStyle ( 'color white' ) ,
7893 ) . toThrowError ( )
@@ -96,4 +111,27 @@ describe('.toHaveStyle', () => {
96111 ` )
97112 expect ( queryByTestId ( 'color-example' ) ) . toHaveStyle ( 'border: 1px solid #fff' )
98113 } )
114+
115+ test ( 'handles different color declaration formats' , ( ) => {
116+ const { queryByTestId} = render ( `
117+ <span data-testid="color-example" style="color: rgba(0, 0, 0, 1); background-color: #000000">Hello World</span>
118+ ` )
119+
120+ expect ( queryByTestId ( 'color-example' ) ) . toHaveStyle ( 'color: #000000' )
121+ expect ( queryByTestId ( 'color-example' ) ) . toHaveStyle (
122+ 'background-color: rgba(0, 0, 0, 1)' ,
123+ )
124+ } )
125+
126+ test ( 'handles nonexistent styles' , ( ) => {
127+ const { container} = render ( `
128+ <div class="label" style="background-color: blue; height: 100%">
129+ Hello World
130+ </div>
131+ ` )
132+
133+ expect ( container . querySelector ( '.label' ) ) . not . toHaveStyle (
134+ 'whatever: anything' ,
135+ )
136+ } )
99137} )
0 commit comments