summaryrefslogtreecommitdiff
path: root/std/testing/asserts.ts
diff options
context:
space:
mode:
Diffstat (limited to 'std/testing/asserts.ts')
-rw-r--r--std/testing/asserts.ts26
1 files changed, 17 insertions, 9 deletions
diff --git a/std/testing/asserts.ts b/std/testing/asserts.ts
index 10e2b9c97..b1164090d 100644
--- a/std/testing/asserts.ts
+++ b/std/testing/asserts.ts
@@ -19,8 +19,16 @@ export class AssertionError extends Error {
}
}
-function format(v: unknown): string {
- let string = globalThis.Deno ? Deno.inspect(v) : String(v);
+export function _format(v: unknown): string {
+ let string = globalThis.Deno
+ ? Deno.inspect(v, {
+ depth: Infinity,
+ sorted: true,
+ trailingComma: true,
+ compact: false,
+ iterableLimit: Infinity,
+ })
+ : String(v);
if (typeof v == "string") {
string = `"${string.replace(/(?=["\\])/g, "\\")}"`;
}
@@ -167,8 +175,8 @@ export function assertEquals(
return;
}
let message = "";
- const actualString = format(actual);
- const expectedString = format(expected);
+ const actualString = _format(actual);
+ const expectedString = _format(expected);
try {
const diffResult = diff(
actualString.split("\n"),
@@ -248,13 +256,13 @@ export function assertStrictEquals<T>(
if (msg) {
message = msg;
} else {
- const actualString = format(actual);
- const expectedString = format(expected);
+ const actualString = _format(actual);
+ const expectedString = _format(expected);
if (actualString === expectedString) {
const withOffset = actualString
.split("\n")
- .map((l) => ` ${l}`)
+ .map((l) => ` ${l}`)
.join("\n");
message = `Values have the same structure but are not reference-equal:\n\n${red(
withOffset
@@ -335,9 +343,9 @@ export function assertArrayContains(
return;
}
if (!msg) {
- msg = `actual: "${format(actual)}" expected to contain: "${format(
+ msg = `actual: "${_format(actual)}" expected to contain: "${_format(
expected
- )}"\nmissing: ${format(missing)}`;
+ )}"\nmissing: ${_format(missing)}`;
}
throw new AssertionError(msg);
}