Chai.js assertions for Jack.js test doubles
// subject:
var out = {
test: function() {},
other: function() {}
};
// test double
jack(out, 'test');
Verify that a function is a test double.
expect(out.test).to.be.a.testDouble();
out.test.should.be.a.testDouble();
expect(out.none).to.not.be.a.testDouble();
out.other.should.not.be.a.testDouble();
Verify that a test double has been invoked.
expect(out.test).to.have.been.invoked();
expect(out.test).invoked();
out.test.should.have.been.invoked();
expect(out.other).to.have.not.been.invoked();
expect(out.other).invoked();
out.other.should.not.have.been.invoked();
Verify that a test double has been called max n
times.
expect(out.test).to.have.been.called.max(1);
out.test.should.have.been.called.max(1);
Verify that a test double has been called min n
times.
expect(out.test).to.have.been.called.min(42);
expect(out.test).to.have.been.called.min(42);
out.test.should.have.been.called.min(42);
out.test.should.have.been.called.min(42);
Verify that a test double has been called exactly n
times.
expect(out.test).to.have.been.called.exactly(42);
expect(out.test).to.have.been.called.exactly(42);
out.test.should.have.been.called.exactly(42);
out.test.should.have.been.called.exactly(42);
Verify that a test double has been called exactly once.
expect(out.test).to.have.been.called.once();
out.test.should.have.been.called.once();
Verify that a test double has been called exactly twice.
expect(out.test).to.have.been.called.twice();
out.test.should.have.been.called.twice();
Verify that a test double has been called on given context.
expect(out.test).to.have.been.called.on(ctx);
out.test.should.have.been.called.on(ctx);
expect(out.test).to.have.not.been.called.on(ctx);
out.test.should.not.have.been.called.on(ctx);
Verify that a test double has been called with given arguments.
expect(out.test).to.have.been.called.with.args('foo', 'bar', 42);
out.test.should.have.been.called.with.args('foo', 'bar', 42);
expect(out.test).to.have.not.been.called.with.args('foo', 'bar', 42);
out.test.should.not.have.been.called.with.args('foo', 'bar', 42);
npm:
npm install jack-chai
component:
component install jackjs/jack-chai
Standalone:
<script src="jack-chai.js></script>
$ npm test
Coverage:
$ npm run coverage
(The MIT License)
Copyright (c) 2013 Veselin Todorov [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.