enzyme-matchers
enzyme-matchers copied to clipboard
Make library work with `render`
Currently we are doing nothing with render
ed components. chai-enzyme is supporting them nicely. We should find a way to support render
ed components.
Does anybody actually use the render
method with enzyme? I'm never use it and wonder if it's really necassary to support..
Hi,
actually I do use render for presentational components. There's often cases I want to test child elements and render is a bit easier. Otherwise you need the sub components imported to be able to assert against them.
const Svg = () => <svg />
const Foo = () => <div><Svg /></div>
With render:
expect(wrapper.find('svg').toBePresent().
With shallow:
import Svg from '...';
expect(wrapper.find(Svg).toBePresent().
Recently switched to Jest, so we might actually do more snapshots, but still.
That's good to know. Thanks for reporting. I think we'all be in an easier place to support this after #39 is done.
@pascalduez you can use find by name with shallow without a problem. What you need to do is search for your component name and not your HTML output.
so your With shallow code will be:
expect(wrapper.find('Svg')).toBePresent();
@luizbon Thanks for the feedback, I'll give it another try.
Still, there are (few) cases where I'd like to test against "real" DOM elements, but well.