Skip to content

Commit

Permalink
[Tests] use better matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jul 21, 2018
1 parent 19f6fbb commit f4d779d
Show file tree
Hide file tree
Showing 14 changed files with 129 additions and 129 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ import Foo from './Foo';
describe('<Foo />', () => {
it('renders three `.foo-bar`s', () => {
const wrapper = render(<Foo />);
expect(wrapper.find('.foo-bar').length).to.equal(3);
expect(wrapper.find('.foo-bar')).to.have.lengthOf(3);
});

it('renders the title', () => {
Expand Down
18 changes: 9 additions & 9 deletions docs/api/ReactWrapper/mount.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ Foo.propTypes = {
};

const wrapper = mount(<Foo id="foo" />);
expect(willMount.callCount).to.equal(1);
expect(didMount.callCount).to.equal(1);
expect(willUnmount.callCount).to.equal(0);
expect(willMount).to.have.property('callCount', 1);
expect(didMount).to.have.property('callCount', 1);
expect(willUnmount).to.have.property('callCount', 0);
wrapper.unmount();
expect(willMount.callCount).to.equal(1);
expect(didMount.callCount).to.equal(1);
expect(willUnmount.callCount).to.equal(1);
expect(willMount).to.have.property('callCount', 1);
expect(didMount).to.have.property('callCount', 1);
expect(willUnmount).to.have.property('callCount', 1);
wrapper.mount();
expect(willMount.callCount).to.equal(2);
expect(didMount.callCount).to.equal(2);
expect(willUnmount.callCount).to.equal(1);
expect(willMount).to.have.property('callCount', 2);
expect(didMount).to.have.property('callCount', 2);
expect(willUnmount).to.have.property('callCount', 1);
```


Expand Down
4 changes: 2 additions & 2 deletions docs/api/ReactWrapper/setProps.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ import sinon from 'sinon';
const spy = sinon.spy(MyComponent.prototype, 'componentWillReceiveProps');

const wrapper = mount(<MyComponent foo="bar" />);
expect(spy.calledOnce).to.equal(false);
expect(spy).to.have.property('callCount', 0);
wrapper.setProps({ foo: 'foo' });
expect(spy.calledOnce).to.equal(true);
expect(spy).to.have.property('callCount', 1);
```


Expand Down
12 changes: 6 additions & 6 deletions docs/api/ReactWrapper/unmount.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ Foo.propTypes = {
id: PropTypes.string.isRequired,
};
const wrapper = mount(<Foo id="foo" />);
expect(willMount.callCount).to.equal(1);
expect(didMount.callCount).to.equal(1);
expect(willUnmount.callCount).to.equal(0);
expect(willMount).to.have.property('callCount', 1);
expect(didMount).to.have.property('callCount', 1);
expect(willUnmount).to.have.property('callCount', 0);
wrapper.unmount();
expect(willMount.callCount).to.equal(1);
expect(didMount.callCount).to.equal(1);
expect(willUnmount.callCount).to.equal(1);
expect(willMount).to.have.property('callCount', 1);
expect(didMount).to.have.property('callCount', 1);
expect(willUnmount).to.have.property('callCount', 1);
```


Expand Down
4 changes: 2 additions & 2 deletions docs/api/ShallowWrapper/setProps.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ import sinon from 'sinon';
const spy = sinon.spy(MyComponent.prototype, 'componentWillReceiveProps');

const wrapper = shallow(<MyComponent foo="bar" />);
expect(spy.calledOnce).to.equal(false);
expect(spy).to.have.property('callCount', 0);
wrapper.setProps({ foo: 'foo' });
expect(spy.calledOnce).to.equal(true);
expect(spy).to.have.property('callCount', 1);
```


Expand Down
4 changes: 2 additions & 2 deletions docs/api/ShallowWrapper/unmount.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Foo.propTypes = {
id: PropTypes.string.isRequired,
};
const wrapper = shallow(<Foo id="foo" />);
expect(spy.calledOnce).to.equal(false);
expect(spy).to.have.property('callCount', 0);
wrapper.unmount();
expect(spy.calledOnce).to.equal(true);
expect(spy).to.have.property('callCount', 1);
```
4 changes: 2 additions & 2 deletions docs/api/mount.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('<Foo />', () => {
it('calls componentDidMount', () => {
sinon.spy(Foo.prototype, 'componentDidMount');
const wrapper = mount(<Foo />);
expect(Foo.prototype.componentDidMount.calledOnce).to.equal(true);
expect(Foo.prototype.componentDidMount).to.have.property('callCount', 1);
});

it('allows us to set props', () => {
Expand All @@ -35,7 +35,7 @@ describe('<Foo />', () => {
<Foo onButtonClick={onButtonClick} />
));
wrapper.find('button').simulate('click');
expect(onButtonClick.calledOnce).to.equal(true);
expect(onButtonClick).to.have.property('callCount', 1);
});
});
```
Expand Down
2 changes: 1 addition & 1 deletion docs/api/shallow.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('<MyComponent />', () => {
const onButtonClick = sinon.spy();
const wrapper = shallow(<Foo onButtonClick={onButtonClick} />);
wrapper.find('button').simulate('click');
expect(onButtonClick.calledOnce).to.equal(true);
expect(onButtonClick).to.have.property('callCount', 1);
});
});

Expand Down
2 changes: 1 addition & 1 deletion docs/guides/lab.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ exports.lab = lab;
lab.suite('A suite', () => {
lab.test('calls componentDidMount', (done) => {
const wrapper = mount(<Foo />);
Code.expect(Foo.prototype.componentDidMount.calledOnce).to.equal(true);
Code.expect(Foo.prototype.componentDidMount.callCount).to.equal(1);
done();
});
});
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/mocha.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ spy(Foo.prototype, 'componentDidMount');
describe('<Foo />', () => {
it('calls componentDidMount', () => {
const wrapper = mount(<Foo />);
expect(Foo.prototype.componentDidMount.calledOnce).to.equal(true);
expect(Foo.prototype.componentDidMount).to.have.property('callCount', 1);
});
});

Expand Down
6 changes: 3 additions & 3 deletions packages/enzyme-test-suite/test/Adapter-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -563,13 +563,13 @@ describe('Adapter', () => {
renderer.render(<Counter />);

let tree = renderer.getNode();
expect(tree.rendered.props.count).to.equal(0);
expect(tree.rendered.props).to.have.property('count', 0);
tree.instance.increment();
tree = renderer.getNode();
expect(tree.rendered.props.count).to.equal(1);
expect(tree.rendered.props).to.have.property('count', 1);
tree.instance.increment();
tree = renderer.getNode();
expect(tree.rendered.props.count).to.equal(2);
expect(tree.rendered.props).to.have.property('count', 2);
});

it('renders basic shallow as well', () => {
Expand Down
52 changes: 26 additions & 26 deletions packages/enzyme-test-suite/test/RSTTraversal-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('RSTTraversal', () => {
const spy = sinon.spy();
const node = $(<div />);
treeForEach(node, spy);
expect(spy.calledOnce).to.equal(true);
expect(spy).to.have.property('callCount', 1);
});

it('should handle a single child', () => {
Expand All @@ -61,7 +61,7 @@ describe('RSTTraversal', () => {
</div>
));
treeForEach(node, spy);
expect(spy.callCount).to.equal(2);
expect(spy).to.have.property('callCount', 2);
});

it('should handle several children', () => {
Expand All @@ -73,7 +73,7 @@ describe('RSTTraversal', () => {
</div>
));
treeForEach(node, spy);
expect(spy.callCount).to.equal(3);
expect(spy).to.have.property('callCount', 3);
});

it('should handle multiple hierarchies', () => {
Expand All @@ -87,7 +87,7 @@ describe('RSTTraversal', () => {
</div>
));
treeForEach(node, spy);
expect(spy.callCount).to.equal(4);
expect(spy).to.have.property('callCount', 4);
});

it('should handle array children', () => {
Expand All @@ -104,7 +104,7 @@ describe('RSTTraversal', () => {
</div>
));
treeForEach(node, spy);
expect(spy.callCount).to.equal(3);
expect(spy).to.have.property('callCount', 3);
const nodes = spy.args.map(arg => arg[0]);
expect(nodes).to.deep.equal([node, divA, divB]);
});
Expand All @@ -130,7 +130,7 @@ describe('RSTTraversal', () => {
</div>
));
treeForEach(node, spy);
expect(spy.callCount).to.equal(5);
expect(spy).to.have.property('callCount', 5);
const nodes = spy.args.map(arg => arg[0]);
expect(nodes).to.deep.equal([node, divA, divB, divC, divD]);
});
Expand All @@ -149,7 +149,7 @@ describe('RSTTraversal', () => {
</div>
));
treeForEach(node, spy);
expect(spy.callCount).to.equal(3);
expect(spy).to.have.property('callCount', 3);
const nodes = spy.args.map(arg => arg[0]);
expect(nodes).to.deep.equal([node, divA, divB]);
});
Expand All @@ -175,7 +175,7 @@ describe('RSTTraversal', () => {
</div>
));
treeForEach(node, spy);
expect(spy.callCount).to.equal(5);
expect(spy).to.have.property('callCount', 5);
const nodes = spy.args.map(arg => arg[0]);
expect(nodes).to.deep.equal([node, divA, divB, divC, divD]);
});
Expand All @@ -194,7 +194,7 @@ describe('RSTTraversal', () => {
</div>
));
treeForEach(node, spy);
expect(spy.callCount).to.equal(3);
expect(spy).to.have.property('callCount', 3);
const nodes = spy.args.map(arg => arg[0]);
expect(nodes).to.deep.equal([node, divA, divB]);
});
Expand All @@ -220,7 +220,7 @@ describe('RSTTraversal', () => {
</div>
));
treeForEach(node, spy);
expect(spy.callCount).to.equal(5);
expect(spy).to.have.property('callCount', 5);
const nodes = spy.args.map(arg => arg[0]);
expect(nodes).to.deep.equal([node, divA, divB, divC, divD]);
});
Expand Down Expand Up @@ -264,7 +264,7 @@ describe('RSTTraversal', () => {
));

treeForEach(node, spy);
expect(spy.callCount).to.equal(3);
expect(spy).to.have.property('callCount', 3);
const nodes = spy.args.map(arg => arg[0]);
expect(nodes).to.deep.equal([node, divA, divB]);
});
Expand All @@ -287,7 +287,7 @@ describe('RSTTraversal', () => {
));

treeForEach(node, spy);
expect(spy.callCount).to.equal(5);
expect(spy).to.have.property('callCount', 5);
const nodes = spy.args.map(arg => arg[0]);
expect(nodes).to.deep.equal([node, divA, divB, divC, divD]);
});
Expand All @@ -306,7 +306,7 @@ describe('RSTTraversal', () => {
));

treeForEach(node, spy);
expect(spy.callCount).to.equal(3);
expect(spy).to.have.property('callCount', 3);
const nodes = spy.args.map(arg => arg[0]);
expect(nodes).to.deep.equal([node, divA, divB]);
});
Expand All @@ -329,7 +329,7 @@ describe('RSTTraversal', () => {
));

treeForEach(node, spy);
expect(spy.callCount).to.equal(5);
expect(spy).to.have.property('callCount', 5);
const nodes = spy.args.map(arg => arg[0]);
expect(nodes).to.deep.equal([node, divA, divB, divC, divD]);
});
Expand All @@ -343,7 +343,7 @@ describe('RSTTraversal', () => {
</div>
));
treeForEach(node, spy);
expect(spy.callCount).to.equal(3);
expect(spy).to.have.property('callCount', 3);
});

it('should pass in the node', () => {
Expand All @@ -357,11 +357,11 @@ describe('RSTTraversal', () => {
</div>
));
treeForEach(node, spy);
expect(spy.callCount).to.equal(4);
expect(spy.args[0][0].type).to.equal('div');
expect(spy.args[1][0].type).to.equal('button');
expect(spy.args[2][0].type).to.equal('nav');
expect(spy.args[3][0].type).to.equal('input');
expect(spy).to.have.property('callCount', 4);
expect(spy.args[0][0]).to.have.property('type', 'div');
expect(spy.args[1][0]).to.have.property('type', 'button');
expect(spy.args[2][0]).to.have.property('type', 'nav');
expect(spy.args[3][0]).to.have.property('type', 'input');
});

});
Expand Down Expand Up @@ -413,9 +413,9 @@ describe('RSTTraversal', () => {

const nodeInTree = tree.rendered[1].rendered[0];
const result = pathToNode(nodeInTree, tree);
expect(result.length).to.equal(2);
expect(result[0].type).to.equal('div');
expect(result[1].type).to.equal('nav');
expect(result).to.have.lengthOf(2);
expect(result[0]).to.have.property('type', 'div');
expect(result[1]).to.have.property('type', 'nav');
});

it('should return trees from the root node except the sibling node', () => {
Expand All @@ -432,9 +432,9 @@ describe('RSTTraversal', () => {

const nodeInTree = tree.rendered[1].rendered[0];
const result = pathToNode(nodeInTree, tree);
expect(result.length).to.equal(2);
expect(result[0].type).to.equal('div');
expect(result[1].type).to.equal('nav');
expect(result).to.have.lengthOf(2);
expect(result[0]).to.have.property('type', 'div');
expect(result[1]).to.have.property('type', 'nav');
});

});
Expand Down

0 comments on commit f4d779d

Please sign in to comment.