Fix message bug with wasCalledWith. Throw on bad arguments to createSpyObj

This commit is contained in:
Josh Susser
2010-02-24 19:27:43 -08:00
parent aef78b1ef1
commit 5e3eb884ca
6 changed files with 98 additions and 28 deletions

View File

@@ -42,7 +42,7 @@ jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) {
var matcherArgs = jasmine.util.argsToArray(arguments);
var result = matcherFunction.apply(this, arguments);
if (this.reportWasCalled_) return result;
var message;
if (!result) {
if (this.message) {
@@ -206,31 +206,32 @@ jasmine.Matchers.prototype.wasNotCalled = function() {
*
*/
jasmine.Matchers.prototype.wasCalledWith = function() {
var expectedArgs = jasmine.util.argsToArray(arguments);
if (!jasmine.isSpy(this.actual)) {
throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.');
}
this.message = function() {
if (this.actual.callCount == 0) {
return "Expected spy to have been called with " + jasmine.pp(arguments) + " but it was never called.";
return "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.";
} else {
return "Expected spy to have been called with " + jasmine.pp(arguments) + " but was called with " + jasmine.pp(this.actual.argsForCall);
return "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall);
}
};
return this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments));
return this.env.contains_(this.actual.argsForCall, expectedArgs);
};
jasmine.Matchers.prototype.wasNotCalledWith = function() {
var expectedArgs = jasmine.util.argsToArray(arguments);
if (!jasmine.isSpy(this.actual)) {
throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.');
}
this.message = function() {
return "Expected spy not to have been called with " + jasmine.pp(arguments) + " but it was";
return "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was";
};
return !this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments));
return !this.env.contains_(this.actual.argsForCall, expectedArgs);
};
/**