Use custom object formatters in spy strategy mismatch errors

This commit is contained in:
Steve Gravrock
2025-06-05 05:44:59 -07:00
parent 63ed2b3948
commit c1cd5c6291
3 changed files with 31 additions and 2 deletions

View File

@@ -9681,7 +9681,7 @@ getJasmineRequireObj().Spy = function(j$) {
"Spy '" +
strategyArgs.name +
"' received a call with arguments " +
j$.basicPrettyPrinter_(Array.prototype.slice.call(args)) +
matchersUtil.pp(Array.prototype.slice.call(args)) +
' but all configured strategies specify other arguments.'
);
} else {

View File

@@ -3855,6 +3855,35 @@ describe('Env integration', function() {
expect(failedExpectations).toEqual([]);
});
it('uses custom object formatters in spy strategy argument mismatch errors', async function() {
env.it('a spec', function() {
env.addCustomObjectFormatter(function(value) {
if (typeof value === 'string') {
return 'custom:' + value;
}
});
const spy = env
.createSpy('foo')
.withArgs('x')
.and.returnValue('');
spy('y');
});
let failedExpectations;
env.addReporter({
specDone: r => (failedExpectations = r.failedExpectations)
});
await env.execute();
expect(failedExpectations).toEqual([
jasmine.objectContaining({
message: jasmine.stringContaining(
'received a call with arguments [ custom:y ]'
)
})
]);
});
describe('#spyOnGlobalErrorsAsync', function() {
const leftInstalledMessage =
'Global error spy was not uninstalled. ' +

View File

@@ -161,7 +161,7 @@ getJasmineRequireObj().Spy = function(j$) {
"Spy '" +
strategyArgs.name +
"' received a call with arguments " +
j$.basicPrettyPrinter_(Array.prototype.slice.call(args)) +
matchersUtil.pp(Array.prototype.slice.call(args)) +
' but all configured strategies specify other arguments.'
);
} else {