36 lines
1.4 KiB
JavaScript
36 lines
1.4 KiB
JavaScript
getJasmineRequireObj().toHaveBeenCalledWith = function(j$) {
|
|
|
|
var getErrorMsg = j$.formatErrorMsg('<toHaveBeenCalledWith>', 'expect(<spyObj>).toHaveBeenCalledWith(...arguments)');
|
|
|
|
function toHaveBeenCalledWith(util, customEqualityTesters) {
|
|
return {
|
|
compare: function() {
|
|
var args = Array.prototype.slice.call(arguments, 0),
|
|
actual = args[0],
|
|
expectedArgs = args.slice(1),
|
|
result = { pass: false };
|
|
|
|
if (!j$.isSpy(actual)) {
|
|
throw new Error(getErrorMsg('Expected a spy, but got ' + j$.pp(actual) + '.'));
|
|
}
|
|
|
|
if (!actual.calls.any()) {
|
|
result.message = function() { return 'Expected spy ' + actual.and.identity() + ' to have been called with ' + j$.pp(expectedArgs) + ' but it was never called.'; };
|
|
return result;
|
|
}
|
|
|
|
if (util.contains(actual.calls.allArgs(), expectedArgs, customEqualityTesters)) {
|
|
result.pass = true;
|
|
result.message = function() { return 'Expected spy ' + actual.and.identity() + ' not to have been called with ' + j$.pp(expectedArgs) + ' but it was.'; };
|
|
} else {
|
|
result.message = function() { return 'Expected spy ' + actual.and.identity() + ' to have been called with ' + j$.pp(expectedArgs) + ' but actual calls were ' + j$.pp(actual.calls.allArgs()).replace(/^\[ | \]$/g, '') + '.'; };
|
|
}
|
|
|
|
return result;
|
|
}
|
|
};
|
|
}
|
|
|
|
return toHaveBeenCalledWith;
|
|
};
|