Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit b99b0a8

Browse files
committed
feat(test): toHaveBeenCalledOnce jasmine matcher
1 parent 431b748 commit b99b0a8

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/testabilityPatch.js

+22
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,28 @@ beforeEach(function(){
9090
return "Expected " + expected + " to match an Error with message " + toJson(messageRegexp);
9191
};
9292
return this.actual.name == 'Error' && messageRegexp.test(this.actual.message);
93+
},
94+
95+
toHaveBeenCalledOnce: function() {
96+
if (arguments.length > 0) {
97+
throw new Error('toHaveBeenCalledOnce does not take arguments, use toHaveBeenCalledWith');
98+
}
99+
100+
if (!jasmine.isSpy(this.actual)) {
101+
throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
102+
}
103+
104+
this.message = function() {
105+
var msg = 'Expected spy ' + this.actual.identity + ' to have been called once, but was ',
106+
count = this.actual.callCount;
107+
return [
108+
count == 0 ? msg + 'never called.'
109+
: msg + 'called ' + count + ' times.',
110+
msg.replace('to have', 'not to have') + 'called once.'
111+
];
112+
};
113+
114+
return this.actual.callCount == 1;
93115
}
94116
});
95117

0 commit comments

Comments
 (0)