Cypress-file-upload: [Bug] File is not an instance of File

Created on 24 Mar 2020  路  8Comments  路  Source: abramenal/cypress-file-upload

Current behavior:

After upgrading to v4 I've got this strange behaviour.
I'm not sure if that's a file-uploader's bug, but it worked before upgrading.
I have this onChange handler:

  onChange = (e) => {
    console.log(e);
    console.log(JSON.stringify(e));
    console.log(e instanceof File, 'isInstance');

    this.setState({
      value: e instanceof File ? e : e.target.value,
      formatError: e instanceof File && !isGoodFormat(e.name),
    });
  };

And the following test code:

cy.get(byDataCy('file-input'))
  .attachFile(getPathToSpecFixture(xlsxFileName));

So, after running the test I'm getting the error:
"Uncaught TypeError: Cannot read property 'value' of undefined"


Stack Trace

stacktrace



Logs from the handler

image


Desired behavior:

I guess we're dealing with some asynchronous processes here.
It would be nice if it worked as before upgrade.

Steps to reproduce: (app code and test code)

TBA

Versions

"cypress": "^4.2.0",
"cypress-file-upload": "^4.0.3",

bug

All 8 comments

Hi @vkhalikov
Thanks for submitting the issue!

It could be related to this line
https://github.com/abramenal/cypress-file-upload/blob/master/src/helpers/attachFileToElement.js#L30

Let me look into and get back with the fix.

We need to somehow create the file with the dom File constructor maybe using cy.window().then(w => w.File)?

Right now I am not able to take a look into the issue properly.
In the meantime, I can suggest to check if the issue exist in v3 (previous major version):
https://github.com/abramenal/cypress-file-upload/tree/v3.5.3
Sorry about that. Not sure I can provide ETA on solving this issue in v4 since I am the only one contributor and maintainer. If you have ideas on fixing that, please feel free to open Pull Request and we can review it together.

Thanks for understanding.

Right now I am not able to take a look into the issue properly.
In the meantime, I can suggest to check if the issue exist in v3 (previous major version):
https://github.com/abramenal/cypress-file-upload/tree/v3.5.3
Sorry about that. Not sure I can provide ETA on solving this issue in v4 since I am the only one contributor and maintainer. If you have ideas on fixing that, please feel free to open Pull Request and we can review it together.

Thanks for understanding.

Yeah, no problem. I didn't encounter the problem on v3.5.3.
Probably will try to find a solution in a while.

Thank you for your work.

I have submitted a PR fixing this and other issues: https://github.com/abramenal/cypress-file-upload/pull/184

I have submitted a PR fixing this and other issues: #184

Oh, that's cool. Thank you very much.

A change of @jdcl32 is released in v4.0.5 so please take a look and let us know if something isn't working still.

Looks like it works. Thank you again for your fix @jdcl32.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sanduteo95 picture sanduteo95  路  7Comments

kammerer picture kammerer  路  7Comments

philjones88 picture philjones88  路  4Comments

zach446 picture zach446  路  3Comments

skjnldsv picture skjnldsv  路  5Comments