From 9e7468f914f10d85e06585d767b63aabe7202f14 Mon Sep 17 00:00:00 2001 From: Walmyr Filho Date: Sun, 23 Jan 2022 00:51:23 +0100 Subject: [PATCH] Improve tests' expectations and add a new one The new test is a work around for the test that depends on issue https://github.com/cypress-io/cypress/issues/19803 to be fixed. --- cypress/integration/selectFile.spec.js | 32 +++++++++++++++----------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/cypress/integration/selectFile.spec.js b/cypress/integration/selectFile.spec.js index ca902cd..ab94a1c 100644 --- a/cypress/integration/selectFile.spec.js +++ b/cypress/integration/selectFile.spec.js @@ -5,7 +5,7 @@ describe('cy.handsOn(".selectFile")', () => { cy.get('input[type="file"]') .selectFile('cypress/fixtures/example.json') .then(input => { - expect(input[0].value).to.contain('example.json') + expect(input[0].files[0].name).to.equal('example.json') }) }) @@ -13,7 +13,7 @@ describe('cy.handsOn(".selectFile")', () => { cy.get('input[type="file"]') .selectFile('cypress/fixtures/example.json', { action: 'drag-drop' }) .then(input => { - expect(input[0].value).to.contain('example.json') + expect(input[0].files[0].name).to.equal('example.json') }) }) @@ -23,7 +23,19 @@ describe('cy.handsOn(".selectFile")', () => { cy.get('input[type="file"]') .selectFile('@exampleFile') .then(input => { - expect(input[0].value).to.contain('example.json') + expect(input[0].files[0].name).to.equal('example.json') + }) + }) + + it('selects a file for upload using an aliased fixture (workaround)', () => { + cy.fixture('example.json', { encoding: null }).as('exampleFile') + cy.get('input[type="file"]') + .selectFile({ + contents: '@exampleFile', + fileName: 'example.json' + }) + .then(input => { + expect(input[0].files[0].name).to.equal('example.json') }) }) @@ -34,11 +46,8 @@ describe('cy.handsOn(".selectFile")', () => { 'cypress/fixtures/example.txt' ]) .then(input => { - console.log(input) - expect(input[0].attributes.multiple.ownerElement.files[0].name) - .to.equal('example.json') - expect(input[0].attributes.multiple.ownerElement.files[1].name) - .to.equal('example.txt') + expect(input[0].files[0].name).to.equal('example.json') + expect(input[0].files[1].name).to.equal('example.txt') }) }) @@ -49,11 +58,8 @@ describe('cy.handsOn(".selectFile")', () => { 'cypress/fixtures/example.txt' ], { action: 'drag-drop' }) .then(input => { - console.log(input) - expect(input[0].attributes.multiple.ownerElement.files[0].name) - .to.equal('example.json') - expect(input[0].attributes.multiple.ownerElement.files[1].name) - .to.equal('example.txt') + expect(input[0].files[0].name).to.equal('example.json') + expect(input[0].files[1].name).to.equal('example.txt') }) }) })