diff options
| author | Vojta Jina | 2011-06-23 16:52:47 +0200 |
|---|---|---|
| committer | Vojta Jina | 2011-08-18 17:41:23 +0200 |
| commit | b99b0a80723ad3a9b43e9ef36869f521eaec19ec (patch) | |
| tree | e2e3d817f9800fddd97fe6ea035c6e14a52714f1 /test | |
| parent | 431b748cac1aa530d68e9bb80e7ceabddf18fcd7 (diff) | |
| download | angular.js-b99b0a80723ad3a9b43e9ef36869f521eaec19ec.tar.bz2 | |
feat(test): toHaveBeenCalledOnce jasmine matcher
Diffstat (limited to 'test')
| -rw-r--r-- | test/testabilityPatch.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 606d29f0..314ba6da 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; } }); |
