cypress-file-upload
cypress-file-upload copied to clipboard
[Bug] Cannot set property name of which has only getter. Where does it come from?
Current behavior:
I wrote a function that allows me to upload files by request when needed (e.g. creating default project without UI clicking). Here's code for it :
cy.wait(1000)
.window()
.then((win) => {
const requestObject = {
method: 'POST',
url: `${(win as any).remote_service_base_url}/my-endpoint`,
headers: {
authorization: 'bearer ' + (win as any).abp.auth.getToken(),
'content-type': 'multipart/form-data',
},
};
cy.fixture(FilesPage.singleFile, 'binary')
.then((file) => Cypress.Blob.binaryStringToBlob(file))
.then((blob) => {
const formData = new FormData();
formData.append('projectId', projectId);
formData.append('comment', '');
formData.append(FilesPage.firstFileName, blob, FilesPage.firstFileName);
cy.request({ ...requestObject, body: formData }).then((response) => {
expect(response.status).to.eq(200);
cy.wait(500);
if (amountOfFiles === 2) {
cy.fixture(`${FilesPage.filesPath}/${FilesPage.secondFileName}`, 'binary')
.then((file) => Cypress.Blob.binaryStringToBlob(file))
.then((blob) => {
const formData = new FormData();
formData.append('projectId', projectId);
formData.append('comment', '');
formData.append(FilesPage.secondFileName, blob, FilesPage.secondFileName);
cy.request({ ...requestObject, body: formData }).then((response) => {
expect(response.status).to.eq(200);
cy.wait(5000);
});
});
}
});
});
});
And this works just fine, it does its job.
However, in next test suite I use cypress-file-upload package and method attachFile
cy.log('before attachFile');
cy.get('p-fileupload input[type="file"]').wait(1000).attachFile({
filePath: filePath,
encoding: 'base64',
});
cy.log('after attachFile');
to upload files using the UI and I get this error. You can see that after using attachFile method the following cy.log is not invoked:

The stack trace for this error is here, I couldn't find hints there:

What I could notice, is that if I skip the function that uploads files by request the attachFile method works as expected.
Desired behavior:
A desired behavior here would be working functionality of attachFile method no matter if upload by request is used or not.
Versions
cypress: 8.3.0 cypress-file-upload: 5.0.8 operating system: windows 10 20H2 browser: Chrome 96
I've seen topic about this error message on stackoverflow, and tried solution, but this doesn't solve the problem.