You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This may duplicate #1297, but considering that issue's age and how its discussion focused on xlink:href, I wanted to report this just in case. Definitely close this if it's a dupe, though!
Current behavior
mounted JSX elements that include a dangerouslySetInnerHTML property will return those inner elements when calling html(), but they cannot be found using find(). (Calling update() on the wrapper doesn't affect this.)
importReactfrom'react';import{mount}from'enzyme';test('find a dangerously-set span',()=>{constwrapper=mount(<divid="myDiv"dangerouslySetInnerHTML={{__html: '<span id="mySpan"></span>'}}/>,);// Success!expect(wrapper.html()).toBe('<div id="myDiv"><span id="mySpan"></span></div>');expect(wrapper.find('div')).toHaveLength(1);expect(wrapper.find('#myDiv')).toHaveLength(1);// Failure!expect(wrapper.find('span')).toHaveLength(1);expect(wrapper.find('#mySpan')).toHaveLength(1);});
Expected behavior
All find() assertions above succeed.
Workaround
Though the toContain Jest matcher will do the trick, this also works in the meantime:
This is somewhat expected, since the stuff in the innerHTML isn't actually part of the react tree. Calling .html() ends up serializing it to a string, so you can't tell what's from a react element or from innerHTML at all :-)
Related open issues
This may duplicate #1297, but considering that issue's age and how its discussion focused on
xlink:href
, I wanted to report this just in case. Definitely close this if it's a dupe, though!Current behavior
mount
ed JSX elements that include adangerouslySetInnerHTML
property will return those inner elements when callinghtml()
, but they cannot be found usingfind()
. (Callingupdate()
on the wrapper doesn't affect this.)Expected behavior
All
find()
assertions above succeed.Workaround
Though the
toContain
Jest matcher will do the trick, this also works in the meantime:Your environment
API
Version
Adapter
The text was updated successfully, but these errors were encountered: