Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuancelin committed May 8, 2016
1 parent 2d631ae commit d57cc90
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions test/ShallowWrapper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2288,6 +2288,33 @@ describe('shallow', () => {
)).to.equal(true);
expect(spy.callCount).to.equal(0);
});
it('should not match on a root node that doesn\'t looks like the rendered one', () => {
const spy = sinon.spy();
const spy2 = sinon.spy();
const wrapper = shallow(
<div>
<div onClick={spy} style={{ fontSize: 12, color: 'red' }}>Hello World</div>
</div>
).first();
expect(wrapper.matchesElement(<div><div>Bonjour le monde</div></div>)).to.equal(false);
expect(wrapper.matchesElement(
<div>
<div onClick={spy} style={{ fontSize: 12, color: 'blue' }}>Hello World</div>
</div>
)).to.equal(false);
expect(wrapper.matchesElement(
<div>
<div onClick={spy2}>Hello World</div>
</div>
)).to.equal(false);
expect(wrapper.matchesElement(
<div>
<div style={{ fontSize: 13, color: 'red' }}>Hello World</div>
</div>
)).to.equal(false);
expect(spy.callCount).to.equal(0);
expect(spy2.callCount).to.equal(0);
});
});

describe('.containsMatchingElement(node)', () => {
Expand Down Expand Up @@ -2369,6 +2396,22 @@ describe('shallow', () => {
expect(spy1.callCount).to.equal(0);
expect(spy2.callCount).to.equal(0);
});
it('should not match on a single node that doesn\'t looks like a rendered one', () => {
const spy1 = sinon.spy();
const spy2 = sinon.spy();
const wrapper = shallow(
<div>
<div onClick={spy1} style={{ fontSize: 12, color: 'red' }}>Hello World</div>
<div onClick={spy2} style={{ fontSize: 13, color: 'blue' }}>Goodbye World</div>
</div>
);
expect(wrapper.containsMatchingElement(
<div>Bonjour le monde</div>
)).to.equal(false);
expect(wrapper.containsMatchingElement(
<div onClick={spy2}>Au revoir le monde</div>
)).to.equal(false);
});
});
describe('.containsAllMatchingElements(nodes)', () => {
it('should match on an array of nodes that all looks like one of rendered nodes', () => {
Expand Down Expand Up @@ -2415,6 +2458,23 @@ describe('shallow', () => {
expect(spy1.callCount).to.equal(0);
expect(spy2.callCount).to.equal(0);
});
it('should not match on nodes that doesn\'t all looks like one of rendered nodes', () => {
const spy1 = sinon.spy();
const spy2 = sinon.spy();
const wrapper = shallow(
<div>
<div onClick={spy1} style={{ fontSize: 12, color: 'red' }}>Hello World</div>
<div onClick={spy2} style={{ fontSize: 13, color: 'blue' }}>Goodbye World</div>
</div>
);
expect(wrapper.containsAllMatchingElements([
<div onClick={spy1} style={{ fontSize: 12, color: 'red' }}>Hello World</div>,
<div onClick={spy1} style={{ fontSize: 12, color: 'red' }}>Bonjour le monde</div>,
<div onClick={spy2}>Goodbye World</div>,
])).to.equal(false);
expect(spy1.callCount).to.equal(0);
expect(spy2.callCount).to.equal(0);
});
});

describe('.containsAnyMatchingElements(nodes)', () => {
Expand Down Expand Up @@ -2462,5 +2522,21 @@ describe('shallow', () => {
expect(spy1.callCount).to.equal(0);
expect(spy2.callCount).to.equal(0);
});
it('should not match on an array with no nodes that looks like a rendered nodes', () => {
const spy1 = sinon.spy();
const spy2 = sinon.spy();
const wrapper = shallow(
<div>
<div onClick={spy1} style={{ fontSize: 12, color: 'red' }}>Hello World</div>
<div onClick={spy2} style={{ fontSize: 13, color: 'blue' }}>Goodbye World</div>
</div>
);
expect(wrapper.containsAnyMatchingElements([
<div onClick={spy1} style={{ fontSize: 12, color: 'red' }}>Bonjour le monde</div>,
<div onClick={spy2}>Au revoir le monde</div>,
])).to.equal(false);
expect(spy1.callCount).to.equal(0);
expect(spy2.callCount).to.equal(0);
});
});
});

0 comments on commit d57cc90

Please sign in to comment.