enzymejs / chai-enzyme

Chai.js assertions and convenience functions for testing React Components with enzyme
MIT License
787 stars 72 forks source link

Cannot convert a Symbol value to a string #214

Closed tagoro9 closed 6 years ago

tagoro9 commented 6 years ago

I was writing some tests for a component that uses the React 16 <Fragment /> component and run into the Cannot convert a Symbol value to a string error when running the tests. I believe that the issue is that React.Fragment uses a Symbol as displayName and the ReactTestWrapper and ShallowTestWrapper inspect method fails to convert this Symbol into a string.

An example of a failing test could be:

const SymbolComponent = class extends React.Component {
  render () {
    return (<div />)
  }
}
SymbolComponent.displayName = Symbol('SymbolComponent')

// The failing test
it('has a div', () => {
  expect(shallow(<SymbolComponent />).find('div').to.exist;
})

I think I have a fix for the Symbol issue. I'm gonna submit a PR soon with it and with some real test cases.