Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

triggerEvent for a "change" event for a file input does not set the value of the input correctly #1248

Open
MariannaAtPlay opened this issue Oct 4, 2022 · 1 comment

Comments

@MariannaAtPlay
Copy link

My app relies on the buildt-in native browser constraint validation API, which uses the value of the input.
Facing an issue with a test with the value of a file input (<input type="file">) being empty ('') after triggering a file upload using triggerEvent, which makes the validation fail

const file = new Blob(['candidate referral with resume upload'],
   { type: 'application/pdf' }
);
file.name = 'Foo-bar.pdf';
await triggerEvent(SELECTORS.FILE_INPUT, 'change',
   { files: [file] }
);

there seems to be a problem with triggerEvent helper, which does not properly set the value of the input

I also tried passing in additional options, but this has not helped:

await triggerEvent(SELECTORS.FILE_INPUT, 'change', {
   files: [file],
   srcElement : { value: 'C:\\fakepath\\Foo-bar.pdf' },
   target : { value: 'C:\\fakepath\\Foo-bar.pdf' }
});

Steps to reproduce the problem:

  • create a test with a file input;
  • trigger a change event using triggerEvent
  • check the value of the input and observing that it's empty
@MariannaAtPlay
Copy link
Author

This PR for a different testing library might provide some ideas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant