Skip to content
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

Get node by className when svg inluded in a mounted component #409

Closed
OttlikG opened this issue May 24, 2016 · 1 comment
Closed

Get node by className when svg inluded in a mounted component #409

OttlikG opened this issue May 24, 2016 · 1 comment

Comments

@OttlikG
Copy link

OttlikG commented May 24, 2016

This code snippet throw the following error:
undefined is not a function (evaluating 'classes.replace(/\s/g, ' ')')
instHasClassName@enzyme/build/MountedTraversal.js:73:0

function TestSVG () {
  let useTag = '<use xlink:href="/path/to/svg/symbol.svg" />';

  return (
    <div className='svg'>
      <svg aria-hidden='true' className='test-svg' dangerouslySetInnerHTML={{__html: useTag }}/>
    </div>
  )
}

let _wrapper = mount(<TestSVG />)
expect(_wrapper.find('.svg').length).to.equal(1)

I can get over of it when I extended the instHasClassName function with the following:

var classes = (0, _reactCompat.findDOMNode)(inst).className || '';
console.log('classes', classes)

if(Object.prototype.toString.call( classes ) === '[object SVGAnimatedString]' && classes.hasOwnProperty('baseVal')) {
  classes = classes.baseVal
}

The console log printed out these:
LOG: 'classes', 'svg'
LOG: 'classes', Object{baseVal: 'test-svg', animVal: 'test-svg'}

@aweary
Copy link
Collaborator

aweary commented May 24, 2016

Hey @OttlikG thanks for the issue. This is a known issue. Our tests run in jsdom which doesn't support SVGs so SVG support was never addressed. You can follow #375 for any updates.

Duplicate of #375.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants