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

Show a friendly error when using TestUtils.Simulate with shallow rendering #5284

Closed
StevenLangbroek opened this issue Oct 26, 2015 · 5 comments · Fixed by #5358
Closed

Show a friendly error when using TestUtils.Simulate with shallow rendering #5284

StevenLangbroek opened this issue Oct 26, 2015 · 5 comments · Fixed by #5358

Comments

@StevenLangbroek
Copy link

I'm doing a simple shallow render on a component which has a button (<a>) with an onClick handler. I can correctly assert most of its properties, but I can't get asserting whether the button has been clicked (by using TestUtils.Simulate.click(output.props.children[1]) and a sinon.spy() passed in as handler) to work. TestUtils doesn't throw any Invariant Violation or whatever other error, the spy just never gets called. When I manually call it through this.props.children[1].props.onClick() it works. Is this expected behavior?

@zpao
Copy link
Member

zpao commented Oct 27, 2015

I'm not up to date with what the interaction is supposed to be with the shallow renderer these days so cc @spicyj

But when you use the shallow renderer you aren't working on a real rendered tree. TestUtils.Simulate.click(output.props.children[1]) especially doesn't look like it should work - remember that props are not rendered output. props.children[1] will be a React Element, not a component instance.

So as your test case seems to be written, yes this is expected.

@sophiebits
Copy link
Collaborator

That's expected. We should probably give a better error message – changing this issue title to reflect that.

@sophiebits sophiebits changed the title TestUtils: Simulate.click incompatible with Shallow Rendering? Show a friendly error when using TestUtils.Simulate with shallow rendering Oct 27, 2015
@StevenLangbroek
Copy link
Author

Is there anything I can do to help with this? I haven't contributed to React yet, but we're investing heavily into in-company knowledge. If you can point me to where to assert this, I'd love to help.

@StevenLangbroek
Copy link
Author

Also, where do I submit PR's for React's website? I could clarify this in the documentation...

@sophiebits
Copy link
Collaborator

The docs/ directory has markdown files that turn into the website. Each page should also have an "Edit on GitHub" button at the top that links you straight to it.

In the ReactTestUtils.js file, you could add an invariant that makes sure React.isValidElement returns false on the passed-in node.

sophiebits added a commit that referenced this issue Nov 3, 2015
…ate-shallow-render

#5284 - Show a friendly error when using TestUtils.Simulate with shallow rendering
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants