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

ShallowWrapper.text() with only   should equal to ' ' #1613

Closed
2 of 10 tasks
nelsonchen90 opened this issue Apr 10, 2018 · 3 comments
Closed
2 of 10 tasks

ShallowWrapper.text() with only   should equal to ' ' #1613

nelsonchen90 opened this issue Apr 10, 2018 · 3 comments

Comments

@nelsonchen90
Copy link

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

  • shallow
  • mount
  • render

Version

library version
Enzyme 3.3.0
React 16.3.0

Adapter

  • 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:
      " "

@nelsonchen90
Copy link
Author

related to #1349 ?

@rardoz
Copy link

rardoz commented May 31, 2018

For now this works

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

Basically nbsps translate to this unix code \u00a0

@ljharb
Copy link
Member

ljharb commented Jun 29, 2018

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.

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

No branches or pull requests

3 participants