Skip to content

Commit

Permalink
Merge branch 'master' into issue-151
Browse files Browse the repository at this point in the history
  • Loading branch information
smacker committed Apr 28, 2016
2 parents 7733cba + 800f70b commit 01aa50a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/api/ShallowWrapper/props.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ expect(wrapper.props().foo).to.equal(10);

#### Related Methods

- [`.prop() => Object`](prop.md)
- [`.prop(key) => Any`](prop.md)
- [`.state([key]) => Any`](state.md)
- [`.context([key]) => Any`](context.md)
3 changes: 2 additions & 1 deletion src/MountedTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export function instHasClassName(inst, className) {
if (!isDOMComponent(inst)) {
return false;
}
const classes = findDOMNode(inst).className || '';
let classes = findDOMNode(inst).className || '';
classes = classes.replace(/\s/g, ' ');
return ` ${classes} `.indexOf(` ${className} `) > -1;
}

Expand Down
3 changes: 2 additions & 1 deletion src/ShallowTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export function childrenOfNode(node) {
}

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

Expand Down
17 changes: 17 additions & 0 deletions test/ReactWrapper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,23 @@ describeWithDOM('mount', () => {
expect(wrapper.is('.foo.bar')).to.equal(true);
});

it('should ignore insignificant whitespace', () => {
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
16 changes: 16 additions & 0 deletions test/ShallowWrapper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,22 @@ describe('shallow', () => {
expect(wrapper.is('.foo.bar')).to.equal(true);
});

it('should ignore insignificant whitespace', () => {
const className = `foo
`;
const wrapper = shallow(<div className={className} />);
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 01aa50a

Please sign in to comment.