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

Document how to test keyboard events? #5

Closed
ronen opened this issue Nov 7, 2018 · 2 comments
Closed

Document how to test keyboard events? #5

ronen opened this issue Nov 7, 2018 · 2 comments

Comments

@ronen
Copy link

ronen commented Nov 7, 2018

Thanks for the super-handy component!

It took me a while to figure out how to test keyboard events when using jsdom. Maybe you'd want to add a section on testing to the README?

FYI see jsdom/jsdom#1634 (comment).

@dlin-me
Copy link
Contributor

dlin-me commented Nov 10, 2018

Hi @ronen , for test, I use simulate-event to simulate keyboard events. It works well for my case.

Testing with jsdom is outside of the scope of this react component.

@dlin-me dlin-me closed this as completed Nov 10, 2018
@elarue53078
Copy link

elarue53078 commented Nov 13, 2018

I'm also trying to test a keyboard event. Here is the text of my test:

it('triggers change in environment with arrow keys', () => {
wrapper.find('t').simulate('keydown', { keyCode: 39 });
expect(defaultProps.setServerTypeHandler).toHaveBeenCalledWith('transient');
});

In this case, the function that contains the call to setServerTypeHandler, which is the function that gets called on the keyboard event, is not getting called in the test - I have checked this in the test coverage, and neither the onKeyEvent nor the function, handleKeyPress, are covered. Is there a reason for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants