aboutsummaryrefslogtreecommitdiffstats
path: root/test/testabilityPatch.js
diff options
context:
space:
mode:
authorVojta Jina2011-06-23 16:52:47 +0200
committerIgor Minar2011-08-19 01:17:09 -0700
commitf6bcbb53f056372d6778fedfc793435fc2e88e11 (patch)
tree3d122d20b30f8b882873f70f6b86207a6dc056db /test/testabilityPatch.js
parent53a4580d956248cfef84c4d11350a54d27211cf7 (diff)
downloadangular.js-f6bcbb53f056372d6778fedfc793435fc2e88e11.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 bb553d68..744aa4cc 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;
}
});