I want to test my file uploading function using Cypress-file-upload but I hurt myself against .attachFile is not a function
I tried two solutions and I still can’t make it works :
JavaScript
x
15
15
1
// 1st one, "find file input" works
2
3
it('find file input', () => {
4
cy.get('input[type="file"')
5
})
6
7
const fileName = 'french_tweets_split.csv';
8
it('Testing csv uploading', () => {
9
cy.fixture(fileName, 'binary')
10
.then(Cypress.Blob.binaryStringToBlob)
11
.then(fileContent => {
12
cy.get("input[type='file']").attachFile({ fileContent, fileName, mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', encoding:'utf8' })
13
})
14
})
15
JavaScript
1
16
16
1
// 2nd one, "find file input" works
2
it('find file input', () => {
3
cy.get('input[type="file"')
4
})
5
6
it('Testing csv uploading', () => {
7
cy.fixture('french_tweets_split.csv').then(fileContent => {
8
cy.get('input[type="file"]').attachFile({
9
fileContent: fileContent.toString(),
10
fileName: 'french_tweets_split.csv',
11
mimeType: 'text/csv'
12
})
13
})
14
})
15
16
What am I doing wrong ?
Advertisement
Answer
You have to import the package:
support/index.js
JavaScript
1
2
1
import 'cypress-file-upload';
2