Skip to content

Cannot "upload" file that does not match accept pattern #1046

@khitrenovich

Description

@khitrenovich

Reproduction example

https://codesandbox.io/s/white-wood-jnes8g

Prerequisites

A user can select a file that does not match the accept type of the input element. We (as programmers) are expected to handle this flow in our code and thus should be able to test this flow with unit tests. However, currently it is impossible to select a file that that does not match the accept type with userEvent.upload() helper - the selection is being silently ignored.

  1. Click on "Choose File"
  2. In the dialog, toggle file type selector from "*.json" to "all files"
  3. Select a non-JSON file
  4. Observe filename as it appears in the output field

Unfortunately, steps 2 and 3 were not captured on the video below, but you can observe the result.

white-wood-jnes8g.-.CodeSandbox.-.Google.Chrome.2022-08-25.14-59-57.mp4

Expected behavior

I expect the unit test in the reproduction example to pass.

Actual behavior

The unit test fails.
As a result, we cannot unit-test a flow where user selects an invalid file.

User-event version

14.4.3

Environment

Testing Library framework:

JS framework:

Test environment:

DOM implementation:

Additional context

No response

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