Skip to content

Commit

Permalink
Improve tests' expectations and add new test
Browse files Browse the repository at this point in the history
The new test is a work around for the test that depends on issue
cypress-io/cypress#19803 to be fixed.
  • Loading branch information
Walmyr Filho committed Jan 22, 2022
1 parent 9f69897 commit 419c6a9
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions cypress/integration/selectFile.spec.js
Expand Up @@ -5,15 +5,15 @@ 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')
})
})

it('selects a file for upload simulating a drag-and-drop', () => {
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')
})
})

Expand All @@ -23,7 +23,20 @@ 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',
mimeType: 'application/json'
})
.then(input => {
expect(input[0].files[0].name).to.equal('example.json')
})
})

Expand All @@ -34,11 +47,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')
})
})

Expand All @@ -49,11 +59,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')
})
})
})

0 comments on commit 419c6a9

Please sign in to comment.