bruderstein / unexpected-react

Plugin for http://unexpected.js.org to enable testing the full React virtual DOM, and also the shallow renderer
http://bruderstein.github.io/unexpected-react
MIT License
186 stars 19 forks source link

Testing stateless functional components #33

Closed ezmiller closed 7 years ago

ezmiller commented 7 years ago

I've been trying for a bit to do some tests for a stateless functional component. I've been trying to use airbnb's enzyme library (now recommended on the FB Test Utils documentation page). Unlike TestUtils, it's able to render stateless components, whereas TestUtils seems to return null when rendering with renderIntoDocument. Normally, I use components rendered using enzyme's mount or shallow functions with unexpected-react by running the assertions on wrapper.node, where wrapper is the result of calling mount or shallow. For normal class-based components, wrapper.node matches one of the selected types that unexpcted-react expects, i.e. ReactElement, RenderedReactElement, and so on. But for stateless components it is StatelessComponent, and this causes unexpected-react to complain that there's "no matching assertion." Any thoughts about how to get around this?

bruderstein commented 7 years ago

There's a section on the readme for that - https://github.com/bruderstein/unexpected-react#stateless-components - does that help?

ezmiller commented 7 years ago

Yes thank you! I'd missed that.