diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index bb553d68490c..744aa4cc174b 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -90,6 +90,28 @@ beforeEach(function(){ return "Expected " + expected + " to match an Error with message " + toJson(messageRegexp); }; return this.actual.name == 'Error' && messageRegexp.test(this.actual.message); + }, + + toHaveBeenCalledOnce: function() { + if (arguments.length > 0) { + throw new Error('toHaveBeenCalledOnce does not take arguments, use toHaveBeenCalledWith'); + } + + if (!jasmine.isSpy(this.actual)) { + throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); + } + + this.message = function() { + var msg = 'Expected spy ' + this.actual.identity + ' to have been called once, but was ', + count = this.actual.callCount; + return [ + count == 0 ? msg + 'never called.' + : msg + 'called ' + count + ' times.', + msg.replace('to have', 'not to have') + 'called once.' + ]; + }; + + return this.actual.callCount == 1; } });