enzyme-matchers icon indicating copy to clipboard operation
enzyme-matchers copied to clipboard

Make library work with `render`

Open blainekasten opened this issue 8 years ago • 5 comments

Currently we are doing nothing with rendered components. chai-enzyme is supporting them nicely. We should find a way to support rendered components.

blainekasten avatar May 19 '16 14:05 blainekasten

Does anybody actually use the render method with enzyme? I'm never use it and wonder if it's really necassary to support..

blainekasten avatar Jun 16 '16 01:06 blainekasten

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.

pascalduez avatar Sep 29 '16 16:09 pascalduez

That's good to know. Thanks for reporting. I think we'all be in an easier place to support this after #39 is done.

blainekasten avatar Oct 02 '16 18:10 blainekasten

@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 avatar Jan 12 '17 02:01 luizbon

@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.

pascalduez avatar Jan 12 '17 09:01 pascalduez