aboutsummaryrefslogtreecommitdiffstats
path: root/test/testabilityPatch.js
diff options
context:
space:
mode:
authorVojta Jina2011-06-23 16:52:47 +0200
committerVojta Jina2011-08-18 17:41:23 +0200
commitb99b0a80723ad3a9b43e9ef36869f521eaec19ec (patch)
treee2e3d817f9800fddd97fe6ea035c6e14a52714f1 /test/testabilityPatch.js
parent431b748cac1aa530d68e9bb80e7ceabddf18fcd7 (diff)
downloadangular.js-b99b0a80723ad3a9b43e9ef36869f521eaec19ec.tar.bz2
feat(test): toHaveBeenCalledOnce jasmine matcher
Diffstat (limited to 'test/testabilityPatch.js')
-rw-r--r--test/testabilityPatch.js22
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;
}
});