@@ -8,32 +8,42 @@ test('.toBeInTheDOM', () => {
8
8
const { queryByTestId} = render ( `
9
9
<span data-testid="count-container">
10
10
<span data-testid="count-value"></span>
11
+ <svg data-testid="svg-element"></svg>
11
12
</span>` )
12
13
13
14
const containerElement = queryByTestId ( 'count-container' )
14
15
const valueElement = queryByTestId ( 'count-value' )
15
16
const nonExistantElement = queryByTestId ( 'not-exists' )
17
+ const svgElement = queryByTestId ( 'svg-element' )
16
18
const fakeElement = { thisIsNot : 'an html element' }
17
19
18
20
// Testing toBeInTheDOM without container
19
21
expect ( valueElement ) . toBeInTheDOM ( )
22
+ expect ( svgElement ) . toBeInTheDOM ( )
20
23
expect ( nonExistantElement ) . not . toBeInTheDOM ( )
21
24
22
25
// negative test cases wrapped in throwError assertions for coverage.
23
26
expect ( ( ) => expect ( valueElement ) . not . toBeInTheDOM ( ) ) . toThrowError ( )
24
27
28
+ expect ( ( ) => expect ( svgElement ) . not . toBeInTheDOM ( ) ) . toThrowError ( )
29
+
25
30
expect ( ( ) => expect ( nonExistantElement ) . toBeInTheDOM ( ) ) . toThrowError ( )
26
31
27
32
expect ( ( ) => expect ( fakeElement ) . toBeInTheDOM ( ) ) . toThrowError ( )
28
33
29
34
// Testing toBeInTheDOM with container
30
35
expect ( valueElement ) . toBeInTheDOM ( containerElement )
36
+ expect ( svgElement ) . toBeInTheDOM ( containerElement )
31
37
expect ( containerElement ) . not . toBeInTheDOM ( valueElement )
32
38
33
39
expect ( ( ) =>
34
40
expect ( valueElement ) . not . toBeInTheDOM ( containerElement ) ,
35
41
) . toThrowError ( )
36
42
43
+ expect ( ( ) =>
44
+ expect ( svgElement ) . not . toBeInTheDOM ( containerElement ) ,
45
+ ) . toThrowError ( )
46
+
37
47
expect ( ( ) =>
38
48
expect ( nonExistantElement ) . toBeInTheDOM ( containerElement ) ,
39
49
) . toThrowError ( )
@@ -53,21 +63,26 @@ test('.toContainElement', () => {
53
63
<span data-testid="parent">
54
64
<span data-testid="child"></span>
55
65
</span>
66
+ <svg data-testid="svg-element"></svg>
56
67
</span>
57
68
` )
58
69
59
70
const grandparent = queryByTestId ( 'grandparent' )
60
71
const parent = queryByTestId ( 'parent' )
61
72
const child = queryByTestId ( 'child' )
73
+ const svgElement = queryByTestId ( 'svg-element' )
62
74
const nonExistantElement = queryByTestId ( 'not-exists' )
63
75
const fakeElement = { thisIsNot : 'an html element' }
64
76
65
77
expect ( grandparent ) . toContainElement ( parent )
66
78
expect ( grandparent ) . toContainElement ( child )
79
+ expect ( grandparent ) . toContainElement ( svgElement )
67
80
expect ( parent ) . toContainElement ( child )
68
81
expect ( parent ) . not . toContainElement ( grandparent )
82
+ expect ( parent ) . not . toContainElement ( svgElement )
69
83
expect ( child ) . not . toContainElement ( parent )
70
84
expect ( child ) . not . toContainElement ( grandparent )
85
+ expect ( child ) . not . toContainElement ( svgElement )
71
86
72
87
// negative test cases wrapped in throwError assertions for coverage.
73
88
expect ( ( ) =>
@@ -96,25 +111,33 @@ test('.toContainElement', () => {
96
111
expect ( ( ) => expect ( grandparent ) . toContainElement ( fakeElement ) ) . toThrowError ( )
97
112
expect ( ( ) => expect ( fakeElement ) . toContainElement ( fakeElement ) ) . toThrowError ( )
98
113
expect ( ( ) => expect ( grandparent ) . not . toContainElement ( child ) ) . toThrowError ( )
114
+ expect ( ( ) =>
115
+ expect ( grandparent ) . not . toContainElement ( svgElement ) ,
116
+ ) . toThrowError ( )
99
117
} )
100
118
101
119
test ( '.toBeEmpty' , ( ) => {
102
120
const { queryByTestId} = render ( `
103
121
<span data-testid="not-empty">
104
122
<span data-testid="empty"></span>
123
+ <svg data-testid="svg-empty"></svg>
105
124
</span>` )
106
125
107
126
const empty = queryByTestId ( 'empty' )
108
127
const notEmpty = queryByTestId ( 'not-empty' )
128
+ const svgEmpty = queryByTestId ( 'svg-empty' )
109
129
const nonExistantElement = queryByTestId ( 'not-exists' )
110
130
const fakeElement = { thisIsNot : 'an html element' }
111
131
112
132
expect ( empty ) . toBeEmpty ( )
133
+ expect ( svgEmpty ) . toBeEmpty ( )
113
134
expect ( notEmpty ) . not . toBeEmpty ( )
114
135
115
136
// negative test cases wrapped in throwError assertions for coverage.
116
137
expect ( ( ) => expect ( empty ) . not . toBeEmpty ( ) ) . toThrowError ( )
117
138
139
+ expect ( ( ) => expect ( svgEmpty ) . not . toBeEmpty ( ) ) . toThrowError ( )
140
+
118
141
expect ( ( ) => expect ( notEmpty ) . toBeEmpty ( ) ) . toThrowError ( )
119
142
120
143
expect ( ( ) => expect ( fakeElement ) . toBeEmpty ( ) ) . toThrowError ( )
@@ -148,13 +171,17 @@ test('.toHaveAttribute', () => {
148
171
<button data-testid="ok-button" type="submit" disabled>
149
172
OK
150
173
</button>
174
+ <svg data-testid="svg-element" width="12"></svg>
151
175
` )
152
176
153
177
expect ( queryByTestId ( 'ok-button' ) ) . toHaveAttribute ( 'disabled' )
154
178
expect ( queryByTestId ( 'ok-button' ) ) . toHaveAttribute ( 'type' )
155
179
expect ( queryByTestId ( 'ok-button' ) ) . not . toHaveAttribute ( 'class' )
156
180
expect ( queryByTestId ( 'ok-button' ) ) . toHaveAttribute ( 'type' , 'submit' )
157
181
expect ( queryByTestId ( 'ok-button' ) ) . not . toHaveAttribute ( 'type' , 'button' )
182
+ expect ( queryByTestId ( 'svg-element' ) ) . toHaveAttribute ( 'width' )
183
+ expect ( queryByTestId ( 'svg-element' ) ) . toHaveAttribute ( 'width' , '12' )
184
+ expect ( queryByTestId ( 'ok-button' ) ) . not . toHaveAttribute ( 'height' )
158
185
159
186
expect ( ( ) =>
160
187
expect ( queryByTestId ( 'ok-button' ) ) . not . toHaveAttribute ( 'disabled' ) ,
@@ -171,6 +198,12 @@ test('.toHaveAttribute', () => {
171
198
expect ( ( ) =>
172
199
expect ( queryByTestId ( 'ok-button' ) ) . toHaveAttribute ( 'type' , 'button' ) ,
173
200
) . toThrowError ( )
201
+ expect ( ( ) =>
202
+ expect ( queryByTestId ( 'svg-element' ) ) . not . toHaveAttribute ( 'width' ) ,
203
+ ) . toThrowError ( )
204
+ expect ( ( ) =>
205
+ expect ( queryByTestId ( 'svg-element' ) ) . not . toHaveAttribute ( 'width' , '12' ) ,
206
+ ) . toThrowError ( )
174
207
expect ( ( ) =>
175
208
expect ( { thisIsNot : 'an html element' } ) . not . toHaveAttribute ( ) ,
176
209
) . toThrowError ( )
@@ -185,6 +218,9 @@ test('.toHaveClass', () => {
185
218
<button data-testid="cancel-button">
186
219
Cancel
187
220
</button>
221
+ <svg data-testid="svg-spinner" class="spinner clockwise">
222
+ <path />
223
+ </svg>
188
224
</div>
189
225
` )
190
226
@@ -195,6 +231,9 @@ test('.toHaveClass', () => {
195
231
expect ( queryByTestId ( 'delete-button' ) ) . toHaveClass ( 'btn btn-danger' )
196
232
expect ( queryByTestId ( 'delete-button' ) ) . not . toHaveClass ( 'btn-link' )
197
233
expect ( queryByTestId ( 'cancel-button' ) ) . not . toHaveClass ( 'btn-danger' )
234
+ expect ( queryByTestId ( 'svg-spinner' ) ) . toHaveClass ( 'spinner' )
235
+ expect ( queryByTestId ( 'svg-spinner' ) ) . toHaveClass ( 'clockwise' )
236
+ expect ( queryByTestId ( 'svg-spinner' ) ) . not . toHaveClass ( 'wise' )
198
237
199
238
expect ( ( ) =>
200
239
expect ( queryByTestId ( 'delete-button' ) ) . not . toHaveClass ( 'btn' ) ,
@@ -217,6 +256,12 @@ test('.toHaveClass', () => {
217
256
expect ( ( ) =>
218
257
expect ( queryByTestId ( 'cancel-button' ) ) . toHaveClass ( 'btn-danger' ) ,
219
258
) . toThrowError ( )
259
+ expect ( ( ) =>
260
+ expect ( queryByTestId ( 'svg-spinner' ) ) . not . toHaveClass ( 'spinner' ) ,
261
+ ) . toThrowError ( )
262
+ expect ( ( ) =>
263
+ expect ( queryByTestId ( 'svg-spinner' ) ) . toHaveClass ( 'wise' ) ,
264
+ ) . toThrowError ( )
220
265
} )
221
266
222
267
test ( '.toHaveStyle' , ( ) => {
0 commit comments