Skip to content

Commit

Permalink
Fixed issue with undefined being wrapped as nodes while constructing …
Browse files Browse the repository at this point in the history
…ReactWrapper (fixes #554) (#576)
  • Loading branch information
Andarist authored and aweary committed Sep 6, 2016
1 parent f40dae8 commit 5049574
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ReactWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ export default class ReactWrapper {
} else {
this.component = null;
this.root = root;
if (!Array.isArray(nodes)) {
if (!nodes) {
this.nodes = [];
} else if (!Array.isArray(nodes)) {
this.node = nodes;
this.nodes = [nodes];
} else {
Expand Down
13 changes: 13 additions & 0 deletions test/ReactWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3005,5 +3005,18 @@ describeWithDOM('mount', () => {
expect(wrapper.name()).to.equal('div');
});
});

describe('.ref()', () => {
it('unavailable ref should return empty nodes', () => {
class WithoutRef extends React.Component {
render() { return <div />; }
}
const wrapper = mount(<WithoutRef />);
const ref = wrapper.ref('not-a-ref');

expect(ref.length).to.equal(0);
expect(ref.isEmpty()).to.equal(true);
});
});
});
});

0 comments on commit 5049574

Please sign in to comment.