Move called into expect.js
This commit is contained in:
@@ -477,6 +477,21 @@
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Assert that a sinon spy was called.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
Assertion.prototype.called =
|
||||
Assertion.prototype.totallyWantsToSpeakToYou = function() {
|
||||
this.assert(
|
||||
this.obj.called
|
||||
, function(){ return 'expected ' + i(this.obj) + ' to be called' }
|
||||
, function(){ return 'expected ' + i(this.obj) + ' not to be called' });
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Assert a failure.
|
||||
*
|
||||
|
||||
@@ -40,4 +40,53 @@ describe('expect.js', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('called', function() {
|
||||
|
||||
var telephone;
|
||||
beforeEach(function() {
|
||||
telephone = sinon.spy();
|
||||
});
|
||||
|
||||
it('has caller ID', function() {
|
||||
telephone();
|
||||
expect(telephone).to.be.called();
|
||||
});
|
||||
|
||||
it('also knows when it\'s speaking to the hand', function() {
|
||||
(function() {})();
|
||||
expect(telephone).not.to.be.called();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('totallyWantsToSpeakToYou', function() {
|
||||
|
||||
var callMeMaybe;
|
||||
beforeEach(function() {
|
||||
callMeMaybe = sinon.spy();
|
||||
});
|
||||
|
||||
it('reminds you that you forgot', function() {
|
||||
expect(function() {
|
||||
expect(callMeMaybe).to.be.called();
|
||||
}).to.throwException();
|
||||
});
|
||||
|
||||
it('gets moody all too quickly', function() {
|
||||
callMeMaybe();
|
||||
expect(function() {
|
||||
expect(callMeMaybe).not.to.be.called();
|
||||
}).to.throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('called and totallyWantsToSpeakToYou', function() {
|
||||
|
||||
it('are best friends forever \u2665', function() {
|
||||
expect(expect(0).to.called).to.be(expect(1).to.totallyWantsToSpeakToYou);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -24,11 +24,6 @@ expect.Assertion.prototype.intersectWith = function(other) {
|
||||
};
|
||||
|
||||
|
||||
expect.Assertion.prototype.called = function() {
|
||||
return this.obj.called;
|
||||
};
|
||||
|
||||
|
||||
expect.Assertion.prototype.equalArray = function(other) {
|
||||
return goog.array.equals(this.obj, other);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user