@@ -15,6 +15,7 @@ describe('.toHaveStyle', () => {
15
15
background-color: black;
16
16
color: white;
17
17
float: left;
18
+ transition: opacity 0.2s ease-out, top 0.3s cubic-bezier(1.175, 0.885, 0.32, 1.275);
18
19
}
19
20
`
20
21
document . body . appendChild ( style )
@@ -30,6 +31,11 @@ describe('.toHaveStyle', () => {
30
31
background-color: blue;
31
32
color: white;
32
33
` )
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
+
33
39
expect ( container . querySelector ( '.label' ) ) . toHaveStyle (
34
40
'background-color:blue;color:white' ,
35
41
)
@@ -53,6 +59,7 @@ describe('.toHaveStyle', () => {
53
59
background-color: black;
54
60
color: white;
55
61
float: left;
62
+ transition: opacity 0.2s ease-out, top 0.3s cubic-bezier(1.175, 0.885, 0.32, 1.275);
56
63
}
57
64
`
58
65
document . body . appendChild ( style )
@@ -63,16 +70,24 @@ describe('.toHaveStyle', () => {
63
70
'font-weight: bold' ,
64
71
) ,
65
72
) . toThrowError ( )
73
+
66
74
expect ( ( ) =>
67
75
expect ( container . querySelector ( '.label' ) ) . not . toHaveStyle ( 'color: white' ) ,
68
76
) . toThrowError ( )
69
77
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
+
70
84
// Make sure the test fails if the css syntax is not valid
71
85
expect ( ( ) =>
72
86
expect ( container . querySelector ( '.label' ) ) . not . toHaveStyle (
73
87
'font-weight bold' ,
74
88
) ,
75
89
) . toThrowError ( )
90
+
76
91
expect ( ( ) =>
77
92
expect ( container . querySelector ( '.label' ) ) . toHaveStyle ( 'color white' ) ,
78
93
) . toThrowError ( )
@@ -96,4 +111,27 @@ describe('.toHaveStyle', () => {
96
111
` )
97
112
expect ( queryByTestId ( 'color-example' ) ) . toHaveStyle ( 'border: 1px solid #fff' )
98
113
} )
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
+ } )
99
137
} )
0 commit comments