@@ -49,13 +49,13 @@ clear to read and to maintain.
49
49
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
50
50
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
51
51
52
+
52
53
- [ Installation] ( #installation )
53
54
- [ Usage] ( #usage )
54
55
- [ With TypeScript] ( #with-typescript )
55
56
- [ Custom matchers] ( #custom-matchers )
56
57
- [ ` toBeDisabled ` ] ( #tobedisabled )
57
58
- [ ` toBeEnabled ` ] ( #tobeenabled )
58
- - [ ` toBeEmpty ` ] ( #tobeempty )
59
59
- [ ` toBeEmptyDOMElement ` ] ( #tobeemptydomelement )
60
60
- [ ` toBeInTheDocument ` ] ( #tobeinthedocument )
61
61
- [ ` toBeInvalid ` ] ( #tobeinvalid )
@@ -76,10 +76,11 @@ clear to read and to maintain.
76
76
- [ ` toHaveDisplayValue ` ] ( #tohavedisplayvalue )
77
77
- [ ` toBeChecked ` ] ( #tobechecked )
78
78
- [ ` toBePartiallyChecked ` ] ( #tobepartiallychecked )
79
- - [ ` toHaveDescription ` ] ( #tohavedescription )
80
79
- [ ` toHaveErrorMessage ` ] ( #tohaveerrormessage )
81
80
- [ Deprecated matchers] ( #deprecated-matchers )
81
+ - [ ` toBeEmpty ` ] ( #tobeempty )
82
82
- [ ` toBeInTheDOM ` ] ( #tobeinthedom )
83
+ - [ ` toHaveDescription ` ] ( #tohavedescription )
83
84
- [ Inspiration] ( #inspiration )
84
85
- [ Other Solutions] ( #other-solutions )
85
86
- [ Guiding Principles] ( #guiding-principles )
@@ -205,31 +206,6 @@ your tests.
205
206
206
207
<hr />
207
208
208
- ### ` toBeEmpty `
209
-
210
- ``` typescript
211
- toBeEmpty ()
212
- ```
213
-
214
- This allows you to assert whether an element has content or not.
215
-
216
- #### Examples
217
-
218
- ``` html
219
- <span data-testid =" not-empty" ><span data-testid =" empty" ></span ></span >
220
- ```
221
-
222
- ``` javascript
223
- expect (getByTestId (' empty' )).toBeEmpty ()
224
- expect (getByTestId (' not-empty' )).not .toBeEmpty ()
225
- ```
226
-
227
- > Note: This matcher is being deprecated due to a name clash with
228
- > ` jest-extended ` . See more info in #216 . In the future, please use only:
229
- > [ ` toBeEmptyDOMElement ` ] ( #toBeEmptyDOMElement )
230
-
231
- <hr />
232
-
233
209
### ` toBeEmptyDOMElement `
234
210
235
211
``` typescript
@@ -1081,58 +1057,6 @@ expect(inputCheckboxIndeterminate).toBePartiallyChecked()
1081
1057
1082
1058
<hr />
1083
1059
1084
- ### ` toHaveDescription `
1085
-
1086
- ``` typescript
1087
- toHaveDescription (text : string | RegExp )
1088
- ```
1089
-
1090
- This allows you to check whether the given element has a description or not.
1091
-
1092
- An element gets its description via the
1093
- [ ` aria-describedby ` attribute] ( https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-describedby_attribute ) .
1094
- Set this to the ` id ` of one or more other elements. These elements may be nested
1095
- inside, be outside, or a sibling of the passed in element.
1096
-
1097
- Whitespace is normalized. Using multiple ids will
1098
- [ join the referenced elements’ text content separated by a space] ( https://www.w3.org/TR/accname-1.1/#mapping_additional_nd_description ) .
1099
-
1100
- When a ` string ` argument is passed through, it will perform a whole
1101
- case-sensitive match to the description text.
1102
-
1103
- To perform a case-insensitive match, you can use a ` RegExp ` with the ` /i `
1104
- modifier.
1105
-
1106
- To perform a partial match, you can pass a ` RegExp ` or use
1107
- ` expect.stringContaining("partial string") ` .
1108
-
1109
- #### Examples
1110
-
1111
- ``` html
1112
- <button aria-label =" Close" aria-describedby =" description-close" >
1113
- X
1114
- </button >
1115
- <div id =" description-close" >
1116
- Closing will discard any changes
1117
- </div >
1118
-
1119
- <button >Delete</button >
1120
- ```
1121
-
1122
- ``` javascript
1123
- const closeButton = getByRole (' button' , {name: ' Close' })
1124
-
1125
- expect (closeButton).toHaveDescription (' Closing will discard any changes' )
1126
- expect (closeButton).toHaveDescription (/ will discard/ ) // to partially match
1127
- expect (closeButton).toHaveDescription (expect .stringContaining (' will discard' )) // to partially match
1128
- expect (closeButton).toHaveDescription (/ ^ closing/ i ) // to use case-insensitive match
1129
- expect (closeButton).not .toHaveDescription (' Other description' )
1130
-
1131
- const deleteButton = getByRole (' button' , {name: ' Delete' })
1132
- expect (deleteButton).not .toHaveDescription ()
1133
- expect (deleteButton).toHaveDescription (' ' ) // Missing or empty description always becomes a blank string
1134
- ```
1135
-
1136
1060
### ` toHaveErrorMessage `
1137
1061
1138
1062
``` typescript
@@ -1187,8 +1111,36 @@ expect(timeInput).not.toHaveErrorMessage('Pikachu!')
1187
1111
1188
1112
## Deprecated matchers
1189
1113
1114
+ ### ` toBeEmpty `
1115
+
1116
+ > Note: This matcher is being deprecated due to a name clash with
1117
+ > ` jest-extended ` . See more info in #216 . In the future, please use only
1118
+ > [ ` toBeEmptyDOMElement ` ] ( #toBeEmptyDOMElement )
1119
+
1120
+ ``` typescript
1121
+ toBeEmpty ()
1122
+ ```
1123
+
1124
+ This allows you to assert whether an element has content or not.
1125
+
1126
+ #### Examples
1127
+
1128
+ ``` html
1129
+ <span data-testid =" not-empty" ><span data-testid =" empty" ></span ></span >
1130
+ ```
1131
+
1132
+ ``` javascript
1133
+ expect (getByTestId (' empty' )).toBeEmpty ()
1134
+ expect (getByTestId (' not-empty' )).not .toBeEmpty ()
1135
+ ```
1136
+
1137
+ <hr />
1138
+
1190
1139
### ` toBeInTheDOM `
1191
1140
1141
+ > This custom matcher is deprecated. Prefer
1142
+ > [ ` toBeInTheDocument ` ] ( #tobeinthedocument ) instead.
1143
+
1192
1144
``` typescript
1193
1145
toBeInTheDOM ()
1194
1146
```
@@ -1219,6 +1171,62 @@ expect(document.querySelector('.cancel-button')).toBeTruthy()
1219
1171
> replacing ` toBeInTheDOM ` to read through the documentation of the proposed
1220
1172
> alternatives to see which use case works better for your needs.
1221
1173
1174
+ ### ` toHaveDescription `
1175
+
1176
+ > This custom matcher is deprecated. Prefer
1177
+ > [ ` toHaveAccessibleDescription ` ] ( #tohaveaccessibledescription ) instead, which
1178
+ > is more comprehensive in implementing the official spec.
1179
+
1180
+ ``` typescript
1181
+ toHaveDescription (text : string | RegExp )
1182
+ ```
1183
+
1184
+ This allows you to check whether the given element has a description or not.
1185
+
1186
+ An element gets its description via the
1187
+ [ ` aria-describedby ` attribute] ( https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-describedby_attribute ) .
1188
+ Set this to the ` id ` of one or more other elements. These elements may be nested
1189
+ inside, be outside, or a sibling of the passed in element.
1190
+
1191
+ Whitespace is normalized. Using multiple ids will
1192
+ [ join the referenced elements’ text content separated by a space] ( https://www.w3.org/TR/accname-1.1/#mapping_additional_nd_description ) .
1193
+
1194
+ When a ` string ` argument is passed through, it will perform a whole
1195
+ case-sensitive match to the description text.
1196
+
1197
+ To perform a case-insensitive match, you can use a ` RegExp ` with the ` /i `
1198
+ modifier.
1199
+
1200
+ To perform a partial match, you can pass a ` RegExp ` or use
1201
+ ` expect.stringContaining("partial string") ` .
1202
+
1203
+ #### Examples
1204
+
1205
+ ``` html
1206
+ <button aria-label =" Close" aria-describedby =" description-close" >
1207
+ X
1208
+ </button >
1209
+ <div id =" description-close" >
1210
+ Closing will discard any changes
1211
+ </div >
1212
+
1213
+ <button >Delete</button >
1214
+ ```
1215
+
1216
+ ``` javascript
1217
+ const closeButton = getByRole (' button' , {name: ' Close' })
1218
+
1219
+ expect (closeButton).toHaveDescription (' Closing will discard any changes' )
1220
+ expect (closeButton).toHaveDescription (/ will discard/ ) // to partially match
1221
+ expect (closeButton).toHaveDescription (expect .stringContaining (' will discard' )) // to partially match
1222
+ expect (closeButton).toHaveDescription (/ ^ closing/ i ) // to use case-insensitive match
1223
+ expect (closeButton).not .toHaveDescription (' Other description' )
1224
+
1225
+ const deleteButton = getByRole (' button' , {name: ' Delete' })
1226
+ expect (deleteButton).not .toHaveDescription ()
1227
+ expect (deleteButton).toHaveDescription (' ' ) // Missing or empty description always becomes a blank string
1228
+ ```
1229
+
1222
1230
## Inspiration
1223
1231
1224
1232
This whole library was extracted out of Kent C. Dodds' [ DOM Testing
0 commit comments