File tree Expand file tree Collapse file tree 4 files changed +58
-2
lines changed Expand file tree Collapse file tree 4 files changed +58
-2
lines changed Original file line number Diff line number Diff line change 1
1
node_modules
2
2
coverage /
3
3
dist /
4
+ .idea /
Original file line number Diff line number Diff line change @@ -249,4 +249,34 @@ describe("userEvent.selectOptions", () => {
249
249
expect ( getByTestId ( "val2" ) . selected ) . toBe ( true ) ;
250
250
expect ( getByTestId ( "val3" ) . selected ) . toBe ( false ) ;
251
251
} ) ;
252
+
253
+ it ( "sets the selected prop on the selected OPTION using OPTGROUPS" , ( ) => {
254
+ const { getByTestId } = render (
255
+ < form >
256
+ < select multiple data-testid = "element" >
257
+ < optgroup label = "test optgroup 1" >
258
+ < option data-testid = "val1" value = "1" >
259
+ 1
260
+ </ option >
261
+ </ optgroup >
262
+ < optgroup label = "test optgroup 2" >
263
+ < option data-testid = "val2" value = "2" >
264
+ 2
265
+ </ option >
266
+ </ optgroup >
267
+ < optgroup label = "test optgroup 1" >
268
+ < option data-testid = "val3" value = "3" >
269
+ 3
270
+ </ option >
271
+ </ optgroup >
272
+ </ select >
273
+ </ form >
274
+ ) ;
275
+
276
+ userEvent . selectOptions ( getByTestId ( "element" ) , [ "1" , "3" ] ) ;
277
+
278
+ expect ( getByTestId ( "val1" ) . selected ) . toBe ( true ) ;
279
+ expect ( getByTestId ( "val2" ) . selected ) . toBe ( false ) ;
280
+ expect ( getByTestId ( "val3" ) . selected ) . toBe ( true ) ;
281
+ } ) ;
252
282
} ) ;
Original file line number Diff line number Diff line change @@ -226,4 +226,29 @@ describe("userEvent.selectOptions", () => {
226
226
expect ( getByTestId ( "val2" ) . selected ) . toBe ( true ) ;
227
227
expect ( getByTestId ( "val3" ) . selected ) . toBe ( false ) ;
228
228
} ) ;
229
+
230
+ it ( "sets the selected prop on the selected OPTION using OPTGROUPS" , ( ) => {
231
+ const { getByTestId } = render ( {
232
+ template : `
233
+ <form>
234
+ <select data-testid="element" multiple>
235
+ <optgroup label="test optgroup 1">
236
+ <option value="1" data-testid="val1">1</option>
237
+ </optgroup>
238
+ <optgroup label="test optgroup 2">
239
+ <option value="2" data-testid="val2">2</option>
240
+ </optgroup>
241
+ <optgroup label="test optgroup 3">
242
+ <option value="3" data-testid="val3">3</option>
243
+ </optgroup>
244
+ </select>
245
+ </form>`
246
+ } ) ;
247
+
248
+ userEvent . selectOptions ( getByTestId ( "element" ) , [ "1" , "3" ] ) ;
249
+
250
+ expect ( getByTestId ( "val1" ) . selected ) . toBe ( true ) ;
251
+ expect ( getByTestId ( "val2" ) . selected ) . toBe ( false ) ;
252
+ expect ( getByTestId ( "val3" ) . selected ) . toBe ( true ) ;
253
+ } ) ;
229
254
} ) ;
Original file line number Diff line number Diff line change @@ -169,8 +169,8 @@ const userEvent = {
169
169
clickElement ( element ) ;
170
170
171
171
const valArray = Array . isArray ( values ) ? values : [ values ] ;
172
- const selectedOptions = Array . from ( element . children ) . filter (
173
- opt => opt . tagName === "OPTION" && valArray . includes ( opt . value )
172
+ const selectedOptions = Array . from ( element . querySelectorAll ( 'option' ) ) . filter (
173
+ opt => valArray . includes ( opt . value )
174
174
) ;
175
175
176
176
if ( selectedOptions . length > 0 ) {
You canβt perform that action at this time.
0 commit comments