Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(testing): improve error messages in mock module (part 2) #5569

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions testing/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ export function assertSpyCalls<
assertIsError(e);
let message = spy.calls.length < expectedCalls
? "Spy not called as much as expected:\n"
: "spy called more than expected:\n";
: "Spy called more than expected:\n";
message += e.message.split("\n").slice(1).join("\n");
throw new AssertionError(message);
}
Expand Down Expand Up @@ -1287,7 +1287,7 @@ export function assertSpyCall<
} catch (e) {
assertIsError(e);
throw new AssertionError(
"spy not called with expected args:\n" +
"Spy not called with expected args:\n" +
e.message.split("\n").slice(1).join("\n"),
);
}
Expand All @@ -1299,8 +1299,8 @@ export function assertSpyCall<
} catch (e) {
assertIsError(e);
let message = expected.self
? "spy not called as method on expected self:\n"
: "spy not expected to be called as method on object:\n";
? "Spy not called as method on expected self:\n"
: "Spy not expected to be called as method on object:\n";
message += e.message.split("\n").slice(1).join("\n");
throw new AssertionError(message);
}
Expand All @@ -1309,20 +1309,20 @@ export function assertSpyCall<
if ("returned" in expected) {
if ("error" in expected) {
throw new TypeError(
"do not expect error and return, only one should be expected",
"Do not expect error and return, only one should be expected",
);
}
if (call.error) {
throw new AssertionError(
"spy call did not return expected value, an error was thrown.",
"Spy call did not return expected value, an error was thrown.",
);
}
try {
assertEquals(call.returned, expected.returned);
} catch (e) {
assertIsError(e);
throw new AssertionError(
"spy call did not return expected value:\n" +
"Spy call did not return expected value:\n" +
e.message.split("\n").slice(1).join("\n"),
);
}
Expand All @@ -1331,7 +1331,7 @@ export function assertSpyCall<
if ("error" in expected) {
if ("returned" in call) {
throw new AssertionError(
"spy call did not throw an error, a value was returned.",
"Spy call did not throw an error, a value was returned.",
);
}
assertIsError(
Expand Down Expand Up @@ -1388,44 +1388,44 @@ export async function assertSpyCallAsync<

if (call.error) {
throw new AssertionError(
"spy call did not return a promise, an error was thrown.",
"Spy call did not return a promise, an error was thrown.",
);
}
if (call.returned !== Promise.resolve(call.returned)) {
throw new AssertionError(
"spy call did not return a promise, a value was returned.",
"Spy call did not return a promise, a value was returned.",
);
}

if (expected) {
if ("returned" in expected) {
if ("error" in expected) {
throw new TypeError(
"do not expect error and return, only one should be expected",
"Do not expect error and return, only one should be expected",
);
}
let expectedResolved;
try {
expectedResolved = await expected.returned;
} catch {
throw new TypeError(
"do not expect rejected promise, expect error instead",
"Do not expect rejected promise, expect error instead",
);
}

let resolved;
try {
resolved = await call.returned;
} catch {
throw new AssertionError("spy call returned promise was rejected");
throw new AssertionError("Spy call returned promise was rejected");
}

try {
assertEquals(resolved, expectedResolved);
} catch (e) {
assertIsError(e);
throw new AssertionError(
"spy call did not resolve to expected value:\n" +
"Spy call did not resolve to expected value:\n" +
e.message.split("\n").slice(1).join("\n"),
);
}
Expand Down
Loading