Skip to content

Commit 84e8ee2

Browse files
allow select to be called with empty array
1 parent 07d4340 commit 84e8ee2

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

packages/driver/cypress/integration/commands/actions/select_spec.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ describe('src/cy/commands/actions/select', () => {
112112
})
113113
})
114114

115+
it('unselects all options if called with empty array', () => {
116+
cy.get('select[name=movies]').select(['apoc', 'br'])
117+
118+
cy.get('select[name=movies]').select([]).then(($select) => {
119+
expect($select.val()).to.deep.eq([])
120+
})
121+
})
122+
115123
// readonly should only be limited to inputs, not checkboxes
116124
it('can select a readonly select', () => {
117125
cy.get('select[name=hunter]').select('gon').then(($select) => {
@@ -505,17 +513,6 @@ describe('src/cy/commands/actions/select', () => {
505513
cy.get('select[name=foods]').select('')
506514
})
507515

508-
it('throws invalid array argument error when called with empty array', (done) => {
509-
cy.on('fail', (err) => {
510-
expect(err.message).to.include('`cy.select()` must be passed an array containing only strings and/or numbers. You passed: `[]`')
511-
expect(err.docsUrl).to.eq('https://on.cypress.io/select')
512-
513-
done()
514-
})
515-
516-
cy.get('select[name=foods]').select([])
517-
})
518-
519516
it('throws invalid array argument error when called with invalid array', (done) => {
520517
cy.on('fail', (err) => {
521518
expect(err.message).to.include('`cy.select()` must be passed an array containing only strings and/or numbers. You passed: `[true,false]`')

packages/driver/src/cy/commands/actions/select.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ export default (Commands, Cypress, cy) => {
2121

2222
if (
2323
_.isArray(valueOrTextOrIndex)
24-
&& (
25-
valueOrTextOrIndex.length === 0
26-
|| !_.some(valueOrTextOrIndex, (val) => _.isNumber(val) || _.isString(val))
27-
)
24+
&& valueOrTextOrIndex.length > 0
25+
&& !_.some(valueOrTextOrIndex, (val) => _.isNumber(val) || _.isString(val))
2826
) {
2927
$errUtils.throwErrByPath('select.invalid_array_argument', { args: { value: JSON.stringify(valueOrTextOrIndex) } })
3028
}
@@ -163,7 +161,7 @@ export default (Commands, Cypress, cy) => {
163161
})
164162
}
165163

166-
if (!values.length) {
164+
if (!values.length && !(_.isArray(valueOrTextOrIndex) && valueOrTextOrIndex.length === 0)) {
167165
$errUtils.throwErrByPath('select.no_matches', {
168166
args: { value: valueOrTextOrIndex.join(', ') },
169167
})

0 commit comments

Comments
 (0)