diff options
Diffstat (limited to 'test/matchers.js')
| -rw-r--r-- | test/matchers.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/matchers.js b/test/matchers.js index 9cd582e1..1e0ae92a 100644 --- a/test/matchers.js +++ b/test/matchers.js @@ -89,6 +89,44 @@ beforeEach(function() { }, + toHaveBeenCalledOnceWith: function() { + var expectedArgs = jasmine.util.argsToArray(arguments); + + if (!jasmine.isSpy(this.actual)) { + throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); + } + + this.message = function() { + if (this.actual.callCount != 1) { + if (this.actual.callCount == 0) { + return [ + 'Expected spy ' + this.actual.identity + ' to have been called with ' + + jasmine.pp(expectedArgs) + ' but it was never called.', + 'Expected spy ' + this.actual.identity + ' not to have been called with ' + + jasmine.pp(expectedArgs) + ' but it was.' + ]; + } + + return [ + 'Expected spy ' + this.actual.identity + ' to have been called with ' + + jasmine.pp(expectedArgs) + ' but it was never called.', + 'Expected spy ' + this.actual.identity + ' not to have been called with ' + + jasmine.pp(expectedArgs) + ' but it was.' + ]; + } else { + return [ + 'Expected spy ' + this.actual.identity + ' to have been called with ' + + jasmine.pp(expectedArgs) + ' but was called with ' + jasmine.pp(this.actual.argsForCall), + 'Expected spy ' + this.actual.identity + ' not to have been called with ' + + jasmine.pp(expectedArgs) + ' but was called with ' + jasmine.pp(this.actual.argsForCall) + ]; + } + }; + + return this.actual.callCount === 1 && this.env.contains_(this.actual.argsForCall, expectedArgs); + }, + + toBeOneOf: function() { return indexOf(arguments, this.actual) !== -1; }, |
