Skip to content

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

@MariannaAtPlay

Description

@MariannaAtPlay

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions