Added wasNotCalledWith matcher, used argsForCall a bit less

This commit is contained in:
Nathan Wilmes & Davis W. Frank 2009-12-21 11:45:49 -08:00
parent 849a4efda8
commit d90852336f
3 changed files with 40 additions and 8 deletions

View File

@ -1201,12 +1201,28 @@ jasmine.Matchers.prototype.wasCalledWith = function() {
}
this.message = function() {
return "Expected spy to have been called with " + jasmine.pp(arguments) + " but was called with " + jasmine.pp(this.actual.argsForCall);
if (this.actual.callCount == 0) {
return "Expected spy to have been called with " + jasmine.pp(arguments) + " 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 this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments));
};
jasmine.Matchers.prototype.wasNotCalledWith = function() {
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 !this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments));
};
/**
* Matcher that checks that the expected item is an element in the actual Array.
*
@ -1437,14 +1453,14 @@ jasmine.PrettyPrinter.prototype.format = function(value) {
this.emitString(value);
} else if (jasmine.isSpy(value)) {
this.emitScalar("spy on " + value.identity);
} else if (value instanceof RegExp) {
this.emitScalar(value.toString());
} else if (typeof value === 'function') {
this.emitScalar('Function');
} else if (typeof value.nodeType === 'number') {
this.emitScalar('HTMLNode');
} else if (value instanceof Date) {
this.emitScalar('Date(' + value + ')');
} else if (value instanceof RegExp) {
this.emitScalar(value.toString());
} else if (value.__Jasmine_been_here_before__) {
this.emitScalar('<circular reference: ' + (jasmine.isArray_(value) ? 'Array' : 'Object') + '>');
} else if (jasmine.isArray_(value) || typeof value == 'object') {
@ -2241,5 +2257,5 @@ jasmine.version_= {
"major": 0,
"minor": 10,
"build": 0,
"revision": 1259251766
"revision": 1261424713
};

View File

@ -33,8 +33,8 @@ describe('Spies', function () {
TestClass.someFunction('foo');
TestClass.someFunction('bar');
expect(TestClass.someFunction.argsForCall[0]).toEqual(['foo']);
expect(TestClass.someFunction.argsForCall[1]).toEqual(['bar']);
expect(TestClass.someFunction.calls[0].args).toEqual(['foo']);
expect(TestClass.someFunction.calls[1].args).toEqual(['bar']);
expect(TestClass.someFunction.mostRecentCall.args).toEqual(['bar']);
});

View File

@ -198,12 +198,28 @@ jasmine.Matchers.prototype.wasCalledWith = function() {
}
this.message = function() {
return "Expected spy to have been called with " + jasmine.pp(arguments) + " but was called with " + jasmine.pp(this.actual.argsForCall);
if (this.actual.callCount == 0) {
return "Expected spy to have been called with " + jasmine.pp(arguments) + " 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 this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments));
};
jasmine.Matchers.prototype.wasNotCalledWith = function() {
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 !this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments));
};
/**
* Matcher that checks that the expected item is an element in the actual Array.
*