@@ -62,7 +62,7 @@ describe("input + menu interactions behavior", () => {
62
62
} ) ;
63
63
64
64
it ( "should not open the menu when is-disabled and an option is selected" , async ( ) => {
65
- const wrapper = mount ( VueSelect , { props : { modelValue : options [ 0 ] . value , options, isDisabled : true } } ) ;
65
+ const wrapper = mount ( VueSelect , { props : { modelValue : options [ 0 ] ? .value , options, isDisabled : true } } ) ;
66
66
67
67
await openMenu ( wrapper , "single-value" ) ;
68
68
@@ -93,11 +93,11 @@ describe("menu keyboard navigation", () => {
93
93
await openMenu ( wrapper ) ;
94
94
await dispatchEvent ( wrapper , new KeyboardEvent ( "keydown" , { key : "ArrowDown" } ) ) ;
95
95
96
- expect ( wrapper . get ( ".focused[role='option']" ) . text ( ) ) . toBe ( options [ 1 ] . label ) ;
96
+ expect ( wrapper . get ( ".focused[role='option']" ) . text ( ) ) . toBe ( options [ 1 ] ? .label ) ;
97
97
98
98
await dispatchEvent ( wrapper , new KeyboardEvent ( "keydown" , { key : "ArrowUp" } ) ) ;
99
99
100
- expect ( wrapper . get ( ".focused[role='option']" ) . text ( ) ) . toBe ( options [ 0 ] . label ) ;
100
+ expect ( wrapper . get ( ".focused[role='option']" ) . text ( ) ) . toBe ( options [ 0 ] ? .label ) ;
101
101
} ) ;
102
102
103
103
it ( "should navigate through the options with the arrow keys and skip disabled options" , async ( ) => {
@@ -112,11 +112,11 @@ describe("menu keyboard navigation", () => {
112
112
await openMenu ( wrapper ) ;
113
113
await dispatchEvent ( wrapper , new KeyboardEvent ( "keydown" , { key : "ArrowDown" } ) ) ;
114
114
115
- expect ( wrapper . get ( ".focused[role='option']" ) . text ( ) ) . toBe ( options [ 2 ] . label ) ;
115
+ expect ( wrapper . get ( ".focused[role='option']" ) . text ( ) ) . toBe ( options [ 2 ] ? .label ) ;
116
116
117
117
await dispatchEvent ( wrapper , new KeyboardEvent ( "keydown" , { key : "ArrowUp" } ) ) ;
118
118
119
- expect ( wrapper . get ( ".focused[role='option']" ) . text ( ) ) . toBe ( options [ 0 ] . label ) ;
119
+ expect ( wrapper . get ( ".focused[role='option']" ) . text ( ) ) . toBe ( options [ 0 ] ? .label ) ;
120
120
} ) ;
121
121
} ) ;
122
122
@@ -142,8 +142,8 @@ describe("single-select option", () => {
142
142
await openMenu ( wrapper ) ;
143
143
await wrapper . get ( "div[role='option']" ) . trigger ( "click" ) ;
144
144
145
- expect ( wrapper . emitted ( "update:modelValue" ) ) . toStrictEqual ( [ [ options [ 0 ] . value ] ] ) ;
146
- expect ( wrapper . get ( ".single-value" ) . element . textContent ) . toBe ( options [ 0 ] . label ) ;
145
+ expect ( wrapper . emitted ( "update:modelValue" ) ) . toStrictEqual ( [ [ options [ 0 ] ? .value ] ] ) ;
146
+ expect ( wrapper . get ( ".single-value" ) . element . textContent ) . toBe ( options [ 0 ] ? .label ) ;
147
147
} ) ;
148
148
149
149
it ( "should select an option when focusing and pressing enter" , async ( ) => {
@@ -152,8 +152,8 @@ describe("single-select option", () => {
152
152
await openMenu ( wrapper ) ;
153
153
await dispatchEvent ( wrapper , new KeyboardEvent ( "keydown" , { key : "Enter" } ) ) ;
154
154
155
- expect ( wrapper . emitted ( "update:modelValue" ) ) . toStrictEqual ( [ [ options [ 0 ] . value ] ] ) ;
156
- expect ( wrapper . get ( ".single-value" ) . element . textContent ) . toBe ( options [ 0 ] . label ) ;
155
+ expect ( wrapper . emitted ( "update:modelValue" ) ) . toStrictEqual ( [ [ options [ 0 ] ? .value ] ] ) ;
156
+ expect ( wrapper . get ( ".single-value" ) . element . textContent ) . toBe ( options [ 0 ] ? .label ) ;
157
157
} ) ;
158
158
159
159
it ( "should select an option when pressing space" , async ( ) => {
@@ -169,8 +169,8 @@ describe("single-select option", () => {
169
169
170
170
await wrapper . vm . $nextTick ( ) ;
171
171
172
- expect ( wrapper . emitted ( "update:modelValue" ) ) . toStrictEqual ( [ [ options [ 0 ] . value ] ] ) ;
173
- expect ( wrapper . get ( ".single-value" ) . element . textContent ) . toBe ( options [ 0 ] . label ) ;
172
+ expect ( wrapper . emitted ( "update:modelValue" ) ) . toStrictEqual ( [ [ options [ 0 ] ? .value ] ] ) ;
173
+ expect ( wrapper . get ( ".single-value" ) . element . textContent ) . toBe ( options [ 0 ] ? .label ) ;
174
174
} ) ;
175
175
176
176
it ( "should remove the selected option when pressing backspace without typing" , async ( ) => {
@@ -179,13 +179,13 @@ describe("single-select option", () => {
179
179
await openMenu ( wrapper ) ;
180
180
await wrapper . get ( "div[role='option']" ) . trigger ( "click" ) ;
181
181
182
- expect ( wrapper . emitted ( "update:modelValue" ) ) . toStrictEqual ( [ [ options [ 0 ] . value ] ] ) ;
183
- expect ( wrapper . get ( ".single-value" ) . element . textContent ) . toBe ( options [ 0 ] . label ) ;
182
+ expect ( wrapper . emitted ( "update:modelValue" ) ) . toStrictEqual ( [ [ options [ 0 ] ? .value ] ] ) ;
183
+ expect ( wrapper . get ( ".single-value" ) . element . textContent ) . toBe ( options [ 0 ] ? .label ) ;
184
184
185
185
await wrapper . get ( "input" ) . trigger ( "mousedown" ) ;
186
186
await dispatchEvent ( wrapper , new KeyboardEvent ( "keydown" , { key : "Backspace" } ) ) ;
187
187
188
- expect ( wrapper . emitted ( "update:modelValue" ) ) . toStrictEqual ( [ [ options [ 0 ] . value ] , [ undefined ] ] ) ;
188
+ expect ( wrapper . emitted ( "update:modelValue" ) ) . toStrictEqual ( [ [ options [ 0 ] ? .value ] , [ undefined ] ] ) ;
189
189
expect ( wrapper . find ( ".single-value" ) . exists ( ) ) . toBe ( false ) ;
190
190
} ) ;
191
191
@@ -195,14 +195,14 @@ describe("single-select option", () => {
195
195
await openMenu ( wrapper ) ;
196
196
await wrapper . get ( "div[role='option']" ) . trigger ( "click" ) ;
197
197
198
- expect ( wrapper . emitted ( "update:modelValue" ) ) . toStrictEqual ( [ [ options [ 0 ] . value ] ] ) ;
199
- expect ( wrapper . get ( ".single-value" ) . element . textContent ) . toBe ( options [ 0 ] . label ) ;
198
+ expect ( wrapper . emitted ( "update:modelValue" ) ) . toStrictEqual ( [ [ options [ 0 ] ? .value ] ] ) ;
199
+ expect ( wrapper . get ( ".single-value" ) . element . textContent ) . toBe ( options [ 0 ] ? .label ) ;
200
200
201
201
await inputSearch ( wrapper , "F" ) ;
202
202
await wrapper . get ( "input" ) . trigger ( "keydown" , { key : "Backspace" } ) ;
203
203
204
- expect ( wrapper . emitted ( "update:modelValue" ) ) . toStrictEqual ( [ [ options [ 0 ] . value ] ] ) ;
205
- expect ( wrapper . get ( ".single-value" ) . element . textContent ) . toBe ( options [ 0 ] . label ) ;
204
+ expect ( wrapper . emitted ( "update:modelValue" ) ) . toStrictEqual ( [ [ options [ 0 ] ? .value ] ] ) ;
205
+ expect ( wrapper . get ( ".single-value" ) . element . textContent ) . toBe ( options [ 0 ] ? .label ) ;
206
206
} ) ;
207
207
208
208
it ( "cannot select an option when there are no matching options" , async ( ) => {
@@ -236,8 +236,8 @@ describe("multi-select options", () => {
236
236
await openMenu ( wrapper ) ;
237
237
await wrapper . get ( "div[role='option']" ) . trigger ( "click" ) ;
238
238
239
- expect ( wrapper . emitted ( "update:modelValue" ) ) . toStrictEqual ( [ [ [ options [ 0 ] . value ] ] ] ) ;
240
- expect ( wrapper . get ( ".multi-value" ) . element . textContent ) . toBe ( options [ 0 ] . label ) ;
239
+ expect ( wrapper . emitted ( "update:modelValue" ) ) . toStrictEqual ( [ [ [ options [ 0 ] ? .value ] ] ] ) ;
240
+ expect ( wrapper . get ( ".multi-value" ) . element . textContent ) . toBe ( options [ 0 ] ? .label ) ;
241
241
} ) ;
242
242
243
243
it ( "should display non-selected remaining options on the list" , async ( ) => {
@@ -284,7 +284,7 @@ describe("clear button", () => {
284
284
await wrapper . get ( "div[role='option']" ) . trigger ( "click" ) ;
285
285
await wrapper . get ( ".clear-button" ) . trigger ( "click" ) ;
286
286
287
- expect ( wrapper . emitted ( "update:modelValue" ) ) . toStrictEqual ( [ [ options [ 0 ] . value ] , [ undefined ] ] ) ;
287
+ expect ( wrapper . emitted ( "update:modelValue" ) ) . toStrictEqual ( [ [ options [ 0 ] ? .value ] , [ undefined ] ] ) ;
288
288
expect ( wrapper . find ( ".clear-button" ) . exists ( ) ) . toBe ( false ) ;
289
289
} ) ;
290
290
@@ -295,7 +295,7 @@ describe("clear button", () => {
295
295
await wrapper . get ( "div[role='option']" ) . trigger ( "click" ) ;
296
296
await wrapper . get ( ".clear-button" ) . trigger ( "click" ) ;
297
297
298
- expect ( wrapper . emitted ( "update:modelValue" ) ) . toStrictEqual ( [ [ [ options [ 0 ] . value ] ] , [ [ ] ] ] ) ;
298
+ expect ( wrapper . emitted ( "update:modelValue" ) ) . toStrictEqual ( [ [ [ options [ 0 ] ? .value ] ] , [ [ ] ] ] ) ;
299
299
expect ( wrapper . find ( ".clear-button" ) . exists ( ) ) . toBe ( false ) ;
300
300
} ) ;
301
301
} ) ;
@@ -357,8 +357,8 @@ describe("component props", () => {
357
357
await openMenu ( wrapper ) ;
358
358
359
359
const optionElements = wrapper . findAll ( "div[role='option']" ) ;
360
- expect ( optionElements [ 0 ] . text ( ) ) . toBe ( "Admin" ) ;
361
- expect ( optionElements [ 1 ] . text ( ) ) . toBe ( "User" ) ;
360
+ expect ( optionElements [ 0 ] ? .text ( ) ) . toBe ( "Admin" ) ;
361
+ expect ( optionElements [ 1 ] ? .text ( ) ) . toBe ( "User" ) ;
362
362
363
363
await wrapper . get ( "div[role='option']" ) . trigger ( "click" ) ;
364
364
@@ -561,7 +561,7 @@ describe("menu autofocus behavior", () => {
561
561
// @ts -expect-error -- ignore type error
562
562
const wrapper = mount ( VueSelect , { props : testCase . props } ) ;
563
563
await openMenu ( wrapper ) ;
564
- expect ( wrapper . get ( ".focused[role='option']" ) . text ( ) ) . toBe ( options [ 0 ] . label ) ;
564
+ expect ( wrapper . get ( ".focused[role='option']" ) . text ( ) ) . toBe ( options [ 0 ] ? .label ) ;
565
565
}
566
566
} ) ;
567
567
@@ -623,7 +623,7 @@ describe("hideSelectedOptions prop", () => {
623
623
await openMenu ( wrapper ) ;
624
624
625
625
expect ( wrapper . findAll ( "div[role='option']" ) . length ) . toBe ( options . length - 1 ) ;
626
- expect ( wrapper . findAll ( "div[role='option']" ) . map ( ( option ) => option . text ( ) ) ) . not . toContain ( options [ 0 ] . label ) ;
626
+ expect ( wrapper . findAll ( "div[role='option']" ) . map ( ( option ) => option . text ( ) ) ) . not . toContain ( options [ 0 ] ? .label ) ;
627
627
} ) ;
628
628
629
629
it ( "should show selected options in menu when hideSelectedOptions is false" , async ( ) => {
@@ -634,7 +634,7 @@ describe("hideSelectedOptions prop", () => {
634
634
await openMenu ( wrapper ) ;
635
635
636
636
expect ( wrapper . findAll ( "div[role='option']" ) . length ) . toBe ( options . length ) ;
637
- expect ( wrapper . findAll ( "div[role='option']" ) . map ( ( option ) => option . text ( ) ) ) . toContain ( options [ 0 ] . label ) ;
637
+ expect ( wrapper . findAll ( "div[role='option']" ) . map ( ( option ) => option . text ( ) ) ) . toContain ( options [ 0 ] ? .label ) ;
638
638
} ) ;
639
639
640
640
it ( "should show all options when in single-select mode regardless of hideSelectedOptions" , async ( ) => {
@@ -645,7 +645,7 @@ describe("hideSelectedOptions prop", () => {
645
645
await openMenu ( wrapper ) ;
646
646
647
647
expect ( wrapper . findAll ( "div[role='option']" ) . length ) . toBe ( options . length ) ;
648
- expect ( wrapper . findAll ( "div[role='option']" ) . map ( ( option ) => option . text ( ) ) ) . toContain ( options [ 0 ] . label ) ;
648
+ expect ( wrapper . findAll ( "div[role='option']" ) . map ( ( option ) => option . text ( ) ) ) . toContain ( options [ 0 ] ? .label ) ;
649
649
} ) ;
650
650
651
651
it ( "should correctly restore hidden options when they are deselected" , async ( ) => {
@@ -658,15 +658,15 @@ describe("hideSelectedOptions prop", () => {
658
658
659
659
// Verify it's hidden from dropdown
660
660
expect ( wrapper . findAll ( "div[role='option']" ) . length ) . toBe ( options . length - 1 ) ;
661
- expect ( wrapper . findAll ( "div[role='option']" ) . map ( ( option ) => option . text ( ) ) ) . not . toContain ( options [ 0 ] . label ) ;
661
+ expect ( wrapper . findAll ( "div[role='option']" ) . map ( ( option ) => option . text ( ) ) ) . not . toContain ( options [ 0 ] ? .label ) ;
662
662
663
663
// Remove the option
664
664
await wrapper . get ( ".multi-value-remove" ) . trigger ( "click" ) ;
665
665
await openMenu ( wrapper ) ;
666
666
667
667
// Verify it's back in the dropdown
668
668
expect ( wrapper . findAll ( "div[role='option']" ) . length ) . toBe ( options . length ) ;
669
- expect ( wrapper . findAll ( "div[role='option']" ) . map ( ( option ) => option . text ( ) ) ) . toContain ( options [ 0 ] . label ) ;
669
+ expect ( wrapper . findAll ( "div[role='option']" ) . map ( ( option ) => option . text ( ) ) ) . toContain ( options [ 0 ] ? .label ) ;
670
670
} ) ;
671
671
672
672
it ( "should correctly filter options when searching with hideSelectedOptions enabled" , async ( ) => {
@@ -744,10 +744,10 @@ describe("exposed component methods and refs", () => {
744
744
} ) ;
745
745
746
746
it ( "should expose clear method for single select" , async ( ) => {
747
- const wrapper = mount ( VueSelect , { props : { modelValue : options [ 0 ] . value , options } } ) ;
747
+ const wrapper = mount ( VueSelect , { props : { modelValue : options [ 0 ] ? .value , options } } ) ;
748
748
749
749
expect ( typeof wrapper . vm . clear ) . toBe ( "function" ) ;
750
- expect ( wrapper . get ( ".single-value" ) . text ( ) ) . toBe ( options [ 0 ] . label ) ;
750
+ expect ( wrapper . get ( ".single-value" ) . text ( ) ) . toBe ( options [ 0 ] ? .label ) ;
751
751
752
752
wrapper . vm . clear ( ) ;
753
753
await wrapper . vm . $nextTick ( ) ;
@@ -756,7 +756,7 @@ describe("exposed component methods and refs", () => {
756
756
} ) ;
757
757
758
758
it ( "should expose clear method for multi select" , async ( ) => {
759
- const wrapper = mount ( VueSelect , { props : { modelValue : [ options [ 0 ] . value ] , isMulti : true , options } } ) ;
759
+ const wrapper = mount ( VueSelect , { props : { modelValue : [ options [ 0 ] ? .value ] , isMulti : true , options } } ) ;
760
760
761
761
expect ( typeof wrapper . vm . clear ) . toBe ( "function" ) ;
762
762
expect ( wrapper . find ( ".multi-value" ) . exists ( ) ) . toBe ( true ) ;
0 commit comments