toHaveNoOtherSpyInteractions message tweaks

This commit is contained in:
Steve Gravrock
2025-01-20 11:31:47 -08:00
parent 7463fe511b
commit 2a7a157713
3 changed files with 14 additions and 15 deletions

View File

@@ -6774,7 +6774,7 @@ getJasmineRequireObj().toHaveNoOtherSpyInteractions = function(j$) {
if (result.pass) { if (result.pass) {
result.message = result.message =
"Expected to have other spy interactions but it didn't."; "Expected a spy object to have other spy interactions but it didn't.";
} else { } else {
const ppUnexpectedCalls = unexpectedCalls const ppUnexpectedCalls = unexpectedCalls
.map( .map(
@@ -6783,9 +6783,9 @@ getJasmineRequireObj().toHaveNoOtherSpyInteractions = function(j$) {
.join(',\n'); .join(',\n');
result.message = result.message =
'Expected to have no other spy interactions, but it had the following calls:\n' + 'Expected a spy object to have no other spy interactions, but it had the following calls:\n' +
ppUnexpectedCalls + ppUnexpectedCalls +
'.\n\n'; '.';
} }
return result; return result;

View File

@@ -40,10 +40,9 @@ describe('toHaveNoOtherSpyInteractions', function() {
let result = matcher.compare(spyObj); let result = matcher.compare(spyObj);
expect(result.pass).toBeFalse(); expect(result.pass).toBeFalse();
// TODO: trim trailing newlines
expect(result.message).toEqual( expect(result.message).toEqual(
'Expected to have no other spy interactions, but it had the following calls:\n' + 'Expected a spy object to have no other spy interactions, but it had the following calls:\n' +
" NewClass.spyA called with [ 'x' ].\n\n" " NewClass.spyA called with [ 'x' ]."
); );
}); });
@@ -64,9 +63,9 @@ describe('toHaveNoOtherSpyInteractions', function() {
let result = matcher.compare(spyObj); let result = matcher.compare(spyObj);
expect(result.pass).toBeFalse(); expect(result.pass).toBeFalse();
expect(result.message).toEqual( expect(result.message).toEqual(
'Expected to have no other spy interactions, but it had the following calls:\n' + 'Expected a spy object to have no other spy interactions, but it had the following calls:\n' +
' NewClass.spyA called with [ ],\n' + ' NewClass.spyA called with [ ],\n' +
' NewClass.spyB called with [ ].\n\n' ' NewClass.spyB called with [ ].'
); );
}); });
@@ -82,7 +81,7 @@ describe('toHaveNoOtherSpyInteractions', function() {
let result = matcher.compare(spyObj); let result = matcher.compare(spyObj);
expect(result.pass).toBeTrue(); expect(result.pass).toBeTrue();
expect(result.message).toEqual( expect(result.message).toEqual(
"Expected to have other spy interactions but it didn't." "Expected a spy object to have other spy interactions but it didn't."
); );
}); });
@@ -106,7 +105,7 @@ describe('toHaveNoOtherSpyInteractions', function() {
let matcher = jasmineUnderTest.matchers.toHaveNoOtherSpyInteractions(); let matcher = jasmineUnderTest.matchers.toHaveNoOtherSpyInteractions();
let spyObj = jasmineUnderTest let spyObj = jasmineUnderTest
.getEnv() .getEnv()
.createSpyObj('NewClass', ['spyA', 'spyB']); .createSpyObj('mySpyObj', ['spyA', 'spyB']);
expect(function() { expect(function() {
matcher.compare(spyObj, 'an argument'); matcher.compare(spyObj, 'an argument');
@@ -117,7 +116,7 @@ describe('toHaveNoOtherSpyInteractions', function() {
let matcher = jasmineUnderTest.matchers.toHaveNoOtherSpyInteractions(); let matcher = jasmineUnderTest.matchers.toHaveNoOtherSpyInteractions();
const spyObj = jasmineUnderTest const spyObj = jasmineUnderTest
.getEnv() .getEnv()
.createSpyObj('NewClass', ['notSpy']); .createSpyObj('mySpyObj', ['notSpy']);
// Removing spy since spy objects cannot be created without spies. // Removing spy since spy objects cannot be created without spies.
spyObj.notSpy = function() {}; spyObj.notSpy = function() {};

View File

@@ -64,7 +64,7 @@ getJasmineRequireObj().toHaveNoOtherSpyInteractions = function(j$) {
if (result.pass) { if (result.pass) {
result.message = result.message =
"Expected to have other spy interactions but it didn't."; "Expected a spy object to have other spy interactions but it didn't.";
} else { } else {
const ppUnexpectedCalls = unexpectedCalls const ppUnexpectedCalls = unexpectedCalls
.map( .map(
@@ -73,9 +73,9 @@ getJasmineRequireObj().toHaveNoOtherSpyInteractions = function(j$) {
.join(',\n'); .join(',\n');
result.message = result.message =
'Expected to have no other spy interactions, but it had the following calls:\n' + 'Expected a spy object to have no other spy interactions, but it had the following calls:\n' +
ppUnexpectedCalls + ppUnexpectedCalls +
'.\n\n'; '.';
} }
return result; return result;