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

Commit

Permalink
feat(test): toHaveBeenCalledOnce jasmine matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtajina authored and IgorMinar committed Aug 19, 2011
1 parent 53a4580 commit f6bcbb5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/testabilityPatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});

Expand Down

0 comments on commit f6bcbb5

Please sign in to comment.