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

Issues testing keyboard events with BlueprintJS NumericInput #336

Closed
j5bot opened this issue Mar 29, 2019 · 6 comments
Closed

Issues testing keyboard events with BlueprintJS NumericInput #336

j5bot opened this issue Mar 29, 2019 · 6 comments
Labels
jsdom Issue with JSDOM environment

Comments

@j5bot
Copy link

j5bot commented Mar 29, 2019

  • react-testing-library version: 6.0.0
  • react version: 16.8.1
  • node version: 8.14.0
  • npm (or yarn) version: yarn 1.12.3

Relevant code or config:

    fireEvent.keyPress(input, generateKeyEvent(input));
    expect(input.value).toBe("203");
    expect(onValueChange.mock.calls.length).toBe(1);

What you did:

Trying to fire a keyPress event on a BlueprintJS NumericInput's input element.

What happened:

Component's onValueChange handler is not triggered.

Reproduction:

https://codesandbox.io/s/w20nqx93pk

Problem description:

I am unable to test simulated user behavior when interacting with my components which leverage BlueprintJS NumericInput component.

Suggested solution:

It is possible this is happening because of the way that the BlueprintJS component handles events. I have opened an issue with them as well, here. Other than that component's event handling, I have come across descriptions of issues with triggering keyboard events in the browser.

@kentcdodds
Copy link
Member

The tests in the codesandbox are passing. What am I missing?

@j5bot
Copy link
Author

j5bot commented Mar 31, 2019 via email

@alexkrolick
Copy link
Collaborator

https://github.com/jsdom/jsdom/blob/master/Changelog.md#1320

The isTrusted property is set by JSDOM in 13.2.0 - can you try adding jest-environment-jsdom-thirteen or pinning the resolution of jsdom to 13+ and see if this still is an issue?

@alexkrolick alexkrolick added the jsdom Issue with JSDOM environment label Mar 31, 2019
@j5bot
Copy link
Author

j5bot commented Apr 4, 2019

Thanks for the tip, @alexkrolick but I can't seem to get the keyboard event sent by fireEvent to have isTrusted: true and trigger the keypress event as if it were a user action.

I found this, which seems to put a nail in the coffin of trying to test the effects of keyboard events: jsdom/jsdom#2102

"No, there are no user actions in jsdom."

While keyboard event listeners will be triggered, the event will not act like a user typing and change the value of an input, and will not trigger a change event handler.

If you can get the keyboard event to actually send isTrusted: true and trigger events as user actions, I would love to see the code.

@kentcdodds
Copy link
Member

This is honestly really unfortunate.

I think you could get around this by running your tests in Karma (and react-testing-library should work there), but then you wont be able to use Jest ☹

Either way there's nothing we can do about this in react-testing-library I think, so I'll close this.

@weyert
Copy link
Contributor

weyert commented Apr 26, 2019

I would suggest to the user-event-npm which handles this all tad bit better. Have a look what we are doing there to try to get reasonable close to how typing in the browser behaves, definitely not perfect, though: https://github.com/Gpx/user-event/blob/68af3552d21d33d600d62239f97da1e2d76ce5e9/src/index.js#L166

lucbpz pushed a commit to lucbpz/react-testing-library that referenced this issue Jul 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jsdom Issue with JSDOM environment
Projects
None yet
Development

No branches or pull requests

4 participants