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

userEvent.upload changeInit option does not update the change event #667

Closed
sydneyjodon-wk opened this issue Apr 28, 2021 · 5 comments · Fixed by #670
Closed

userEvent.upload changeInit option does not update the change event #667

sydneyjodon-wk opened this issue Apr 28, 2021 · 5 comments · Fixed by #670
Labels
bug Something isn't working released

Comments

@sydneyjodon-wk
Copy link
Contributor

Hello 👋 I’m new to testing-library, but am really enjoying it so far! I’m currently running into an issue when using the changeInit option on userEvent.upload.

  • @testing-library/user-event version: 13.1.5
  • @testing-library/jest-dom version: 5.11.9
  • @testing-library/react version: 11.2.5

Relevant code or config

import "@testing-library/jest-dom/extend-expect";
import React from "react";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";

test("upload file", () => {
  const file = new File([], "hello.png");
  var clickEvents = [];
  var changeEvents = [];

  render(
    <div>
      <label htmlFor="file-uploader">Upload file:</label>
      <input
        id="file-uploader"
        type="file"
        onClick={(e) => clickEvents.push(e)}
        onChange={(e) => changeEvents.push(e)}
      />
    </div>
  );
  const input = screen.getByLabelText(/upload file/i);
  userEvent.upload(input, file, {
    clickInit: { shiftKey: true },
    changeInit: { cancelable: true }
  });

  expect(input.files[0].name).toStrictEqual("hello.png");
  expect(clickEvents[0].shiftKey).toBeTruthy();
  expect(changeEvents[0].cancelable).toBeTruthy(); // this check fails
});

What I did:

I wrote a test using the changeInit option on userEvent.upload and expected that the change event would have the updated cancelable value (similar to clickInit with shiftKey).

What happened:

The change event was not updated like I expected it to be and the test failed.

Test results:

expect(received).toBeTruthy()

Received: false

  48 |   expect(input.files[0].name).toStrictEqual("hello.png");
  49 |   expect(clickEvents[0].shiftKey).toBeTruthy();
> 50 |   expect(changeEvents[0].cancelable).toBeTruthy();
  51 | });

Reproduction repository:

Sandbox link

Suggested solution:

I think the issue might have to do with this line. Maybe it could be something like ...init?.changeInit instead?

@ph-fritsche
Copy link
Member

Thanks a lot for the report ❤️
You're 100% correct. Should deconstructure init.changeInit.

@ph-fritsche
Copy link
Member

@all-contributors add @sydneyjodon-wk bug

@allcontributors
Copy link
Contributor

@ph-fritsche

I've put up a pull request to add @sydneyjodon-wk! 🎉

@ph-fritsche ph-fritsche added the bug Something isn't working label Apr 29, 2021
@github-actions
Copy link

🎉 This issue has been resolved in version 13.1.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

@sydneyjodon-wk
Copy link
Contributor Author

@ph-fritsche Thank you for fixing that so quickly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants