diff --git a/packages/driver/cypress/integration/commands/actions/select_spec.js b/packages/driver/cypress/integration/commands/actions/select_spec.js index 98a03d3f0d0c..b6737582b133 100644 --- a/packages/driver/cypress/integration/commands/actions/select_spec.js +++ b/packages/driver/cypress/integration/commands/actions/select_spec.js @@ -54,9 +54,15 @@ describe('src/cy/commands/actions/select', () => { }) }) + it('can handle valid index 0', () => { + cy.get('select[name=maps]').select(0).then(($select) => { + expect($select).to.have.value('de_dust2') + }) + }) + it('can select an array of values', () => { - cy.get('select[name=movies]').select(['apoc', 'br']).then(($select) => { - expect($select.val()).to.deep.eq(['apoc', 'br']) + cy.get('select[name=movies]').select(['apoc', 'br', 'co']).then(($select) => { + expect($select.val()).to.deep.eq(['apoc', 'br', 'co']) }) }) @@ -366,6 +372,39 @@ describe('src/cy/commands/actions/select', () => { cy.get('select').select('foo') }) + it('throws when called with no arguments', (done) => { + cy.on('fail', (err) => { + expect(err.message).to.include('`cy.select()` must be passed a string, number, or array as its 1st argument. You passed: `undefined`.') + expect(err.docsUrl).to.eq('https://on.cypress.io/select') + + done() + }) + + cy.get('select[name=maps]').select() + }) + + it('throws when called with null', (done) => { + cy.on('fail', (err) => { + expect(err.message).to.include('`cy.select()` must be passed a string, number, or array as its 1st argument. You passed: `null`.') + expect(err.docsUrl).to.eq('https://on.cypress.io/select') + + done() + }) + + cy.get('select[name=maps]').select(null) + }) + + it('throws when called with invalid type', (done) => { + cy.on('fail', (err) => { + expect(err.message).to.include('`cy.select()` must be passed a string, number, or array as its 1st argument. You passed: `true`.') + expect(err.docsUrl).to.eq('https://on.cypress.io/select') + + done() + }) + + cy.get('select[name=foods]').select(true) + }) + it('throws on anything other than a select', (done) => { cy.on('fail', (err) => { expect(err.message).to.include('`cy.select()` can only be called on a ``') @@ -455,6 +494,39 @@ describe('src/cy/commands/actions/select', () => { cy.get('select[name=foods]').select('foo') }) + it('throws invalid argument error when called with empty string', (done) => { + cy.on('fail', (err) => { + expect(err.message).to.include('`cy.select()` failed because it could not find a single `