mirror of
https://github.com/cypress-io/cypress.git
synced 2026-02-11 17:50:01 -06:00
allow select to be called with empty array (#18329)
This commit is contained in:
@@ -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) => {
|
||||
@@ -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]`')
|
||||
|
||||
@@ -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) } })
|
||||
}
|
||||
@@ -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(', ') },
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user