UNPKG

chai-spies-augment

Version:

Additions to chai-spies, adding utilities to inspect args and check if a spy was called with a partial object

101 lines (82 loc) 3.63 kB
'use strict'; var _chai = require('chai'); var _chai2 = _interopRequireDefault(_chai); var _calledWithObjectContaining = require('./called-with-object-containing'); var _calledWithObjectContaining2 = _interopRequireDefault(_calledWithObjectContaining); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } _chai2.default.use(_calledWithObjectContaining2.default); describe('Called With Object Containing', function () { var spy = void 0; beforeEach(function () { spy = _chai2.default.spy(); }); it('should assert method is being used on a spy', function () { var notASpy = {}; (0, _chai.expect)(function () { (0, _chai.expect)(notASpy).to.not.have.been.called.with.objectContaining({ a: 'b' }); }).to.throw('expected [object Object] to be a spy'); }); it('should throw useful error if spy has not been called', function () { (0, _chai.expect)(function () { (0, _chai.expect)(spy).not.to.have.been.called.with.objectContaining({ a: 'b' }); }).to.throw('Spy has not been called'); }); context('Match object has single property', function () { context('Spy called with exact match', function () { it('should assert true', function () { spy({ a: 'b' }); (0, _chai.expect)(spy).to.have.been.called.with.objectContaining({ a: 'b' }); }); }); context('Spy called with object containing match', function () { it('should assert true', function () { spy({ a: 'b', c: 'd' }); (0, _chai.expect)(spy).to.have.been.called.with.objectContaining({ a: 'b' }); }); }); context('Spy called with nothing like a match', function () { it('should assert false', function () { spy('not even an object'); (0, _chai.expect)(spy).not.to.have.been.called.with.objectContaining({ a: 'b' }); }); }); context('Spy has been called with an object with same property but different value', function () { it('should assert false', function () { spy({ a: 'hmm not a match' }); (0, _chai.expect)(spy).not.to.have.been.called.with.objectContaining({ a: 'b' }); }); }); }); context('Match object has multiple properties', function () { context('Spy called with exact match', function () { it('should assert true', function () { spy({ a: 'b', c: 'd' }); (0, _chai.expect)(spy).to.have.been.called.with.objectContaining({ a: 'b', c: 'd' }); }); }); context('Spy called with object containing match', function () { it('should assert true', function () { spy({ a: 'b', c: 'd', e: 'f' }); (0, _chai.expect)(spy).to.have.been.called.with.objectContaining({ a: 'b', c: 'd' }); }); }); context('Spy called with nothing like a match', function () { it('should assert false', function () { spy('not even an object'); (0, _chai.expect)(spy).not.to.have.been.called.with.objectContaining({ a: 'b', c: 'd' }); }); }); context('Spy has been called with an object with a partial match', function () { it('should assert false', function () { spy({ a: 'b' }); (0, _chai.expect)(spy).not.to.have.been.called.with.objectContaining({ a: 'b', c: 'd' }); }); context('and one property which matches but whose value is different', function () { it('should assert false', function () { spy({ a: 'b', c: 'hmm not a match' }); (0, _chai.expect)(spy).not.to.have.been.called.with.objectContaining({ a: 'b', c: 'd' }); }); }); }); }); });