Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix some error reporting

  • Loading branch information...
commit 666d659357882f70baaea71e030a1067f586fe51 1 parent fa01dfc
@felixge authored
View
4 lib/expectation/callee_expectation.js
@@ -33,6 +33,10 @@ CalleeExpectation.prototype.getFunctionName = function() {
return this._fakeFunction.getName();
};
+CalleeExpectation.prototype.getFakeFunction = function() {
+ return this._fakeFunction;
+};
+
// This expectation is fulfilled by default, so it doesn't keep a
// times(0, n) expectation from being recognized as fulfilled.
CalleeExpectation.prototype.isFulfilled = function() {
View
10 lib/expected_call.js
@@ -59,6 +59,11 @@ ExpectedCall.prototype.andReturn = function(val) {
return this;
};
+ExpectedCall.prototype.calleeOfFakeCall = function(fakeCall) {
+ var calleeExpectation = this._expectations.first('isType', 'callee');
+ return calleeExpectation.getFakeFunction() === fakeCall.getFakeFunction();
+};
+
ExpectedCall.prototype.getError = function(fakeCall) {
var errors = this._expectations
.map('getError', fakeCall, this)
@@ -76,7 +81,8 @@ ExpectedCall.prototype.score = function(fakeCall) {
};
ExpectedCall.prototype.hasPotential = function() {
- return this._expectations.some('hasPotential');
+ var timesExpectation = this._expectations.first('isType', 'times');
+ return timesExpectation.hasPotential();
};
ExpectedCall.prototype.isSatisfied = function() {
@@ -98,7 +104,7 @@ ExpectedCall.prototype.fulfill = function(fakeCall) {
};
ExpectedCall.prototype.getSignature = function() {
- var calleeExpectation = this._expectations.first('getType', 'callee');
+ var calleeExpectation = this._expectations.first('isType', 'callee');
var name = calleeExpectation.getFunctionName();
var newExpectation = this._expectations.first('isType', 'viaNew');
View
2  lib/fake.js
@@ -197,7 +197,7 @@ Fake.prototype._handleFakeCall = function(fakeCall) {
if (!expectedCall) {
expectedCall = this._next
- .filter('isSatisfied')
+ .filter('calleeOfFakeCall', fakeCall)
.last();
}
View
9 test/integration/fake/test-expect.js
@@ -23,3 +23,12 @@ var fake = fake.create();
fake.reset();
})();
+
+(function testNoCallsExpected() {
+ fake.expect(object, 'a', 0);
+ fake.stub(object, 'b', 0);
+
+ assert.throws(function() {
+ object.b();
+ }, /no calls were expected/i);
+})();
Please sign in to comment.
Something went wrong with that request. Please try again.