question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onBeforeInput not triggering with userEvent.type

See original GitHub issue
  • @testing-library/user-event version: 13.5.0
  • Testing Framework and version: jest 26.6.0

  • DOM Environment: jsdom 16.5.1

  • Node version: 15.12.0

Relevant code or config

// Does not pass
it("should trigger onBeforeInput", () => {
  const mockOnBeforeInput = jest.fn();
  render(<App onBeforeInput={mockOnBeforeInput} inputTestId="test-input" />);
  const inputElem = screen.getByTestId("test-input");
  userEvent.type(inputElem, "hello input");
  // onBeforeInput is not triggered at all when calling userEvent.type
  expect(mockOnBeforeInput).toBeCalledTimes(11);
});

What you did: use userEvent.type in a test to type ‘hello input’ into an input text field

What happened: onBeforeInput is not triggered when calling userEvent.type

image

Reproduction repository: https://codesandbox.io/s/sad-feather-8rbd7k?file=/src/App.test.js

I don’t know if this issue is solvable since I assume userEvent.type is only concerned with triggering key events (whereas onBeforeInput and onInput are specific to input elements), but I’m just raising this in the hopes that there is a possible fix 🙏

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
ph-fritschecommented, Sep 14, 2022

The configure function is invoked and reexported from @testing-library/dom by @testing-library/react. If it just were imported by your setup, that would make no difference to importing anything else from @testing-library/react. However, if it is invoked, the configuration by @testing-library/react already took place and you might override the asyncWrapper and/or eventWrapper.

1reaction
jwarykowskicommented, Sep 14, 2022

Hey @ph-fritsche, thanks for the feedback, I’ve had a quick look and noticed that we import this in quite a few places so I’ll update and try again. Thanks for your help, greatly appreciated 🙇

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Testing Library: UserEvent.type not working
Problem: UserEvent.type is not working. I have a simple test where I get the textbox, which works, but when trying to type in...
Read more >
user-event - Bountysource
userEvent.type does not dispatch change events on input with @testing-library/dom $ 0 ... onBeforeInput is not triggered at all when calling userEvent.type ......
Read more >
Utility APIs - Testing Library
Type into an input element. You should use keyboard() if you want to just simulate pressing buttons on the keyboard. You can use...
Read more >
@testing-library/user-event - npm
Simulates the keyboard events described by text . This is similar to userEvent.type() but without any clicking or changing the selection range.
Read more >
Why you should test with user-event | Philipp Fritsche
It's been a while since I stumbled over Testing Library and their user-event package. Something not working yet at the time bugged me...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found