Files
jasmine/src/core/matchers/toHaveBeenCalled.js
Gregg Van Hove 21655a82c9 Use prototype for spy strategy for better memory management
- Also convert `identity` to a property from a method
2017-11-30 17:30:20 -08:00

39 lines
1.1 KiB
JavaScript

getJasmineRequireObj().toHaveBeenCalled = function(j$) {
var getErrorMsg = j$.formatErrorMsg('<toHaveBeenCalled>', 'expect(<spyObj>).toHaveBeenCalled()');
/**
* {@link expect} the actual (a {@link Spy}) to have been called.
* @function
* @name matchers#toHaveBeenCalled
* @example
* expect(mySpy).toHaveBeenCalled();
* expect(mySpy).not.toHaveBeenCalled();
*/
function toHaveBeenCalled() {
return {
compare: function(actual) {
var result = {};
if (!j$.isSpy(actual)) {
throw new Error(getErrorMsg('Expected a spy, but got ' + j$.pp(actual) + '.'));
}
if (arguments.length > 1) {
throw new Error(getErrorMsg('Does not take arguments, use toHaveBeenCalledWith'));
}
result.pass = actual.calls.any();
result.message = result.pass ?
'Expected spy ' + actual.and.identity + ' not to have been called.' :
'Expected spy ' + actual.and.identity + ' to have been called.';
return result;
}
};
}
return toHaveBeenCalled;
};