-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Render Testing dangerouslySetInnerHTML containing an xlink #1298
Comments
It seems like the kind of nonstandard property that React itself is removing. What version of react? |
This was with my upgrade from React 15 (tested w/ enzyme v2) to React 16 (tested w/ enzyme v3) |
@peter-mouland by upgrading both react and enzyme at once, it's pretty hard to know where the problem is. Could you get enzyme 3 with react 15 passing first, and then upgrade to React 16? |
sure, that's fair - i'm in the UK though so not right now ;) |
I can confirm: tests it('renders the use href using xlink (needed for safari) original', () => {
const component = render(<Svg use={defaultMockProps.id} />)
const use = component.find('use')
expect(use.prop('xlink:href')).toBe(`#${defaultMockProps.id}`)
})
it('renders the use href using xlink (needed for safari) w/ render', () => {
const component = render(<Svg use={defaultMockProps.id} />)
expect(component.html()).toContain(`xlink:href="#${defaultMockProps.id}"`)
})
it('renders the use href using xlink (needed for safari) w/ shallow', () => {
const component = shallow(<Svg use={defaultMockProps.id} />)
expect(component.html()).toContain(`xlink:href="#${defaultMockProps.id}"`)
}) result: enzyme 2 and React 15.6.2 // original
*pass*
// w/render
*pass*
// w/shallow
*pass* result: enzyme 3 React 15 (same result with React 16) // original
Expected value to be (using ===):
"#wugjaco"
Received:
undefined
// w/render
Expected string:
"<svg><use href=\"#wugjaco\"/></svg>"
To contain value:
"xlink:href=\"#wugjaco\""
// w/shallow
*pass*
(original fails as find('use').prop('xlink:href') returns length 0) |
Thanks! That means it's not specific to the react 16 adapter, which means it's a v3 issue. @aweary, could you take a look into this one? |
Provide a simpler test case: it('render `xlink:href` in html of dangerouslySetInnerHTML', () => {
const xlinkId = 'TEST';
const svg = `<svg><use xlink:href="#${xlinkId}" /></svg>`;
const wrapper = render(<span dangerouslySetInnerHTML={{ __html: svg }} />);
expect(wrapper.html()).contain(`xlink:href="#${xlinkId}"`);
}); It looks like it's an issue in cheerio side. cheerio converts See cheeriojs/cheerio#1101 . |
In that case, closing in favor of #1297 which already is tracking that cheerio issue. |
I have recently rewrote a test (from v2 to v3) and found now that
xlink
is removed from the dangerouslySetInnerHTML ...I'm not convinced this is really enzyme removing this, but it does seem to render correctly in the browser.
Have i found an issue, or am I missing something?
Thanks for your time.
Example component:
Failing Test
Result:
React:
This test works using
shallow
:The text was updated successfully, but these errors were encountered: