mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-04-30 11:24:43 +00:00
feat(test): toHaveBeenCalledOnce jasmine matcher
This commit is contained in:
parent
53a4580d95
commit
f6bcbb53f0
1 changed files with 22 additions and 0 deletions
|
|
@ -90,6 +90,28 @@ beforeEach(function(){
|
||||||
return "Expected " + expected + " to match an Error with message " + toJson(messageRegexp);
|
return "Expected " + expected + " to match an Error with message " + toJson(messageRegexp);
|
||||||
};
|
};
|
||||||
return this.actual.name == 'Error' && messageRegexp.test(this.actual.message);
|
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;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue