From 1cdfa3b9601c199ec0b45096b38e26350eca744f Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Tue, 8 Nov 2011 01:56:42 -0800 Subject: feat(deferreds/promises): Q-like deferred/promise implementation with a ton of specs --- test/matchers.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'test/matchers.js') 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; }, -- cgit v1.2.3