hasChildTextNode doesn’t handle numeric children
The code at assertions.js#L34-L35 doesn’t handle numeric children and throws an uncaught error trying to access properties of the number object in these instances.
This is a seemingly common thing in the wild. Things like react-data-components emit elements whose only children are numbers.
I’m happy to provide a PR, but not sure what the best option is here, but it may be to handle numeric children as strings. That said, this perhaps brings up a question about how “implicit” string conversions should be handled.
Upon further reading, this seems to be handled (just not in the way I’d personally expect) by #10.
Can you expand on what you expected? Further, not sure what value there would be in making assertions against numeric children.
More or less a matter of laziness. If you render a number in a react component, it’s generally displayed as text.
While I don’t consider myself an expert, and can’t be entirely certain there would be no negative effects effects, I’d suggest a good approach would be to update the tests in that file so we only check;
- if the child is null or undefined
- if the child is an image
- if the child is a React component and has children
Then if it hasn’t matched any of those, treat the child as a string. As far as I’m aware, anything which didn’t fit those checks would be treated as such by React, anyway.
Alternately, react-a11y could mandate that strings must be strings, requiring lots of toString() calls in existing code.
Thanks for following up. Why don't you put together a PR representing the change you'd like to see so we can review it?