Skip to content

Commit

Permalink
Merge pull request #1350 from idanilt/master
Browse files Browse the repository at this point in the history
Change ShallowWrapper.text() trim spaces with same behavior as ReactWrapper.text()
  • Loading branch information
ljharb authored Nov 14, 2017
2 parents 3f2eab6 + 3077c0b commit d82cb47
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
27 changes: 26 additions & 1 deletion packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import { expect } from 'chai';
import sinon from 'sinon';
import { shallow, render, ShallowWrapper } from 'enzyme';
import { shallow, render, ShallowWrapper, mount } from 'enzyme';
import { ITERATOR_SYMBOL, withSetStateAllowed, sym } from 'enzyme/build/Utils';

import './_helpers/setupAdapters';
Expand Down Expand Up @@ -1633,6 +1633,31 @@ describe('shallow', () => {
matchesRender(<div>&gt;</div>);
});

it('should handle spaces with same behavior as ReactWrapper.text()', () => {
const Space = (
<div>
<div> test </div>
<div>Hello


World
</div>
<div>Hello World</div>
<div>Hello
World
</div>
<div>Hello World</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;</div>
</div>
);

const wrapper = shallow(Space);
const mounted = mount(Space);

expect(wrapper.text()).to.equal(mounted.text());
});

describeIf(!REACT013, 'stateless function components', () => {
it('should handle nodes with mapped children', () => {
const Foo = props => (
Expand Down
3 changes: 1 addition & 2 deletions packages/enzyme/src/RSTTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,5 @@ export function getTextFromNode(node) {
}

return childrenOfNode(node).map(getTextFromNode)
.join('')
.replace(/\s+/, ' ');
.join('');
}

0 comments on commit d82cb47

Please sign in to comment.