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: Better errors for methods when passing in arguments with wrong type #6493

Closed
petetnt opened this issue Apr 12, 2016 · 0 comments
Closed

Comments

@petetnt
Copy link
Contributor

petetnt commented Apr 12, 2016

Rather minor issue, but the fix should be simple enough so I thought that I'd file this anyway:

When using react-addons-testutils, sometimes I write simple errors such as

TestUtils.scryRenderedDOMComponentsWithClass("foo")

// expected:
TestUtils.scryRenderedDOMComponentsWithClass(reactComponentInstance, "foo")

This throws a stack trace of ~80 lines with a type error of TypeError: Cannot read property 'split' of undefined. Fixing this is trivial (and the first line of the stack trace points to the offending line as expected), but the error itself isn't really obvious.

Some others such as scryRenderedDOMComponentsWithTag don't throw until findAllInRenderedTree is reached, which throws a bit more helpful error of Error: findAllInRenderedTree(...): instance must be a composite component(…).

Would it make sense to check that the arguments passed are valid and throw immediately if they aren't, so the user would end up with errors along the lines of scryRenderedDOMComponentsWithClass: first argument must be an instance of ReactComponent?

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