I have a simple <p> component that has a dangerouslySetInnerHTML and when doing a shallow render of:
<div>
<p dangerouslySetInnerHTML={{ __html: 'blah' }} />
</div>
_wrapper.find('p').text() doesn't return 'blah' as expected.
_wrapper.find('p').html() returns 'blah' wrapped in the <p> tag.
Have a branch that proves that text() doesn't work
Thanks for the report @silasb. Just curious, does it work as expected with mount? I'll look into this and try to reproduce when I get a chance.
Forgot to include the failing tests in my branch. I added a test for mount as well and it passes just fine.
You could try using the .render() function like this on the shallow rendered object: https://github.com/airbnb/enzyme/blob/master/docs/api/ShallowWrapper/render.md
You could try using the .render() function like this on the shallow rendered object: https://github.com/airbnb/enzyme/blob/master/docs/api/ShallowWrapper/render.md
This doesn't work for me in v3, apparently due to this issue.
@JasoonS that worked for me, thanks!
It works for me if I render() first. (v3+)
it("does something", () => {
expect(component.render().text()).toEqual('assertion');
});
[v3.7.0]
I'm having the same issue but with mount. I tried to make it working by render() and then text() or html() and didn't work.
It generate the primitive text but not the element I've passed.
@raulfdm .text() and .html() are different (text wouldn't show html, and .html calls render); but i'd expect the element to show up in .debug() somehow. does it not?
Most helpful comment
You could try using the .render() function like this on the shallow rendered object: https://github.com/airbnb/enzyme/blob/master/docs/api/ShallowWrapper/render.md