Skip to content

Upload with empty filelist no longer fires event (breaks simulation of "user closes file dialog") #574

@schoeneu

Description

@schoeneu
  • @testing-library/user-event version: 12.8.1
  • Testing Framework and version: jest 26
  • DOM Environment: jsdom 16.4.0

Sample code that breaks:

    user.upload(fileChooser, new File([validInputFile], 'test.txt'));
    await waitFor(() =>
      expect(logicThatTriggersOnChange).toBeCalled(),
    );

    user.upload(fileChooser, []);
// this no longer succeeds.
    await waitFor(() =>
      expect(logicThatTriggersOnChange).toBeCalled(),
    );

Problem description:

12.8.1 no longer fires an event when triggering upload with an empty file list. This means I can't simulate the user interaction "user opens file dialog, then aborts without selecting a file" anymore.

Probably caused by https://github.com/testing-library/user-event/pull/562/files#diff-0d02b9dbce9a4eb9b8e939cd4606e84f9348a9a289903a87636ecc6ad25ad413R22 in #562

The PR in question explicitly tests this behaviour and wants no event to be fired: https://github.com/testing-library/user-event/pull/562/files#diff-96272a98d39b469bbb095ed9a8be60a76ff04515be29afad4cdc45814d640d1eR195

... but my tests on both Firefox and Chrome show that they do fire an event (and go back to "no file selected") when a file was selected previously and then the upload dialog is opened again and aborted afterwards.

Suggested solution:

Reintroduce firing an "empty" event.

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