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

[TestUtils] Simulate.<event> doesn't set the synthetic event type #6100

Closed
quantizor opened this issue Feb 23, 2016 · 1 comment
Closed

[TestUtils] Simulate.<event> doesn't set the synthetic event type #6100

quantizor opened this issue Feb 23, 2016 · 1 comment

Comments

@quantizor
Copy link
Contributor

SyntheticEvent.type is undefined when received by the handler. Or the nativeEvent type for that matter.

Needs to be added in here somewhere:

var event = new SyntheticEvent(

I realize that it's not sustainable to have to set all the possible fields for a simulated event, but the type at least makes sense for verification that you're getting the right sort of event.

@gaearon
Copy link
Collaborator

gaearon commented Mar 28, 2016

You can optionally pass eventData as a second argument:

ReactTestUtils.Simulate.change(node, { type: 'change' });

It’s not just limited to type. You can add more data to the synthetic event exactly the same way. It will get attached to the event instance with an assign() call.

While there is no official way to also pass a fake nativeEvent, you should be able to use exactly the same technique for it:

ReactTestUtils.Simulate.change(node, {
  type: 'change',
  nativeEvent: {
    type: 'change',
    target: node,
  },
});

This would bypass the normalization code but you probably don’t need it in tests anyway.

I am closing this but please let me know if I missed something.

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

No branches or pull requests

2 participants