Enzyme: ShallowWrapper.text() with only   should equal to ' '

Created on 10 Apr 2018  路  3Comments  路  Source: enzymejs/enzyme

Current behavior

if the element only contains  , when reading it with shallowWrapper.text(), it doesn't equal to ' ' (one space)

Expected behavior

  should equal to ' ' (one space)

Your environment

API

  • [x] shallow
  • [ ] mount
  • [ ] render

Version

| library | version
| ---------------- | -------
| Enzyme | 3.3.0
| React | 16.3.0

Adapter

  • [x] enzyme-adapter-react-16
  • [ ] enzyme-adapter-react-15
  • [ ] enzyme-adapter-react-15.4
  • [ ] enzyme-adapter-react-14
  • [ ] enzyme-adapter-react-13
  • [ ] enzyme-adapter-react-helper
  • [ ] others ( )

code snippet

// component
const Foo = () => (
  <div className={styles.foo}>
    &nbsp;
  </div>
);


// test
 const container = shallow(<Foo />);
  expect(container.find(`.${styles.foo}`).text()).toEqual(' ');


// test result
expect(received).toEqual(expected)

    Expected value to equal:
      " "
    Received:
      " "

shallow Tests invalid

Most helpful comment

For now this works

expect(container.find(`.${styles.foo}`).text()).toEqual('\u00a0');

Basically nbsps translate to this unix code \u00a0

All 3 comments

related to #1349 ?

For now this works

expect(container.find(`.${styles.foo}`).text()).toEqual('\u00a0');

Basically nbsps translate to this unix code \u00a0

I think the issue is that perhaps your literal non-breaking space in your tests is getting transformed to a normal one.

I've added explicit tests for the character codes generated by non-breaking spaces, and they both are already passing.

Was this page helpful?
0 / 5 - 0 ratings