Skip to content

Commit

Permalink
Treat all siginiciant whitespace as spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Dail authored and Brandon Dail committed Apr 26, 2016
1 parent 973cc00 commit 7838753
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/MountedTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ export function instHasClassName(inst, className) {
if (!isDOMComponent(inst)) {
return false;
}
const classes = findDOMNode(inst).className || '';
return ` ${classes.trim()} `.indexOf(` ${className} `) > -1;
let classes = findDOMNode(inst).className || '';
classes = classes.replace(/\s/g, ' ').trim();
return ` ${classes} `.indexOf(` ${className} `) > -1;
}

export function instHasId(inst, id) {
Expand Down
5 changes: 3 additions & 2 deletions src/ShallowTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ export function childrenOfNode(node) {
}

export function hasClassName(node, className) {
const classes = propsOfNode(node).className || '';
return ` ${classes.trim()} `.indexOf(` ${className} `) > -1;
let classes = propsOfNode(node).className || '';
classes = classes.replace(/\s/g, ' ').trim();
return ` ${classes} `.indexOf(` ${className} `) > -1;
}

export function treeForEach(tree, fn) {
Expand Down
10 changes: 9 additions & 1 deletion test/ReactWrapper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -901,12 +901,20 @@ describeWithDOM('mount', () => {
});

it('should ignore insignificant whitespace', () => {
const className = `foo
const className = `
foo
`;
const wrapper = mount(<div className={className} />);
expect(wrapper.is('.foo')).to.equal(true);
});

it('should handle all significant whitespace', () => {
const className = `foo bar
baz`;
const wrapper = mount(<div className={className} />);
expect(wrapper.is('.foo.bar.baz')).to.equal(true);
});

it('should return false when selector does not match', () => {
const wrapper = mount(<div className="bar baz" />);
expect(wrapper.is('.foo')).to.equal(false);
Expand Down
7 changes: 7 additions & 0 deletions test/ShallowWrapper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,13 @@ describe('shallow', () => {
expect(wrapper.is('.foo')).to.equal(true);
});

it('should handle all significant whitespace', () => {
const className = `foo bar
baz`;
const wrapper = shallow(<div className={className} />);
expect(wrapper.is('.foo.bar.baz')).to.equal(true);
});

it('should return false when selector does not match', () => {
const wrapper = shallow(<div className="bar baz" />);
expect(wrapper.is('.foo')).to.equal(false);
Expand Down

0 comments on commit 7838753

Please sign in to comment.