Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ describe('src/cy/commands/actions/select', () => {
})
})

it('unselects all options if called with empty array', () => {
cy.get('select[name=movies]').select(['apoc', 'br'])

cy.get('select[name=movies]').select([]).then(($select) => {
expect($select.val()).to.deep.eq([])
})
})

// readonly should only be limited to inputs, not checkboxes
it('can select a readonly select', () => {
cy.get('select[name=hunter]').select('gon').then(($select) => {
Expand Down Expand Up @@ -505,17 +513,6 @@ describe('src/cy/commands/actions/select', () => {
cy.get('select[name=foods]').select('')
})

it('throws invalid array argument error when called with empty array', (done) => {
cy.on('fail', (err) => {
expect(err.message).to.include('`cy.select()` must be passed an array containing only strings and/or numbers. You passed: `[]`')
expect(err.docsUrl).to.eq('https://on.cypress.io/select')

done()
})

cy.get('select[name=foods]').select([])
})

it('throws invalid array argument error when called with invalid array', (done) => {
cy.on('fail', (err) => {
expect(err.message).to.include('`cy.select()` must be passed an array containing only strings and/or numbers. You passed: `[true,false]`')
Expand Down
8 changes: 3 additions & 5 deletions packages/driver/src/cy/commands/actions/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ export default (Commands, Cypress, cy) => {

if (
_.isArray(valueOrTextOrIndex)
&& (
valueOrTextOrIndex.length === 0
|| !_.some(valueOrTextOrIndex, (val) => _.isNumber(val) || _.isString(val))
)
&& valueOrTextOrIndex.length > 0
&& !_.some(valueOrTextOrIndex, (val) => _.isNumber(val) || _.isString(val))
) {
$errUtils.throwErrByPath('select.invalid_array_argument', { args: { value: JSON.stringify(valueOrTextOrIndex) } })
}
Expand Down Expand Up @@ -163,7 +161,7 @@ export default (Commands, Cypress, cy) => {
})
}

if (!values.length) {
if (!values.length && !(_.isArray(valueOrTextOrIndex) && valueOrTextOrIndex.length === 0)) {
$errUtils.throwErrByPath('select.no_matches', {
args: { value: valueOrTextOrIndex.join(', ') },
})
Expand Down