summaryrefslogtreecommitdiff
path: root/std/testing/asserts.ts
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2020-07-11 05:52:18 +0100
committerGitHub <noreply@github.com>2020-07-11 00:52:18 -0400
commit5ec41cbcc2778a80b6ee91f0c391fc2edec0a8e0 (patch)
tree71d44638e72871624aef63deca19eb271ffa8604 /std/testing/asserts.ts
parent40d081d3d9f64bcd2524da86fb78808ac1d7b888 (diff)
feat(Deno.inspect): Add sorted, trailingComma, compact and iterableLimit to InspectOptions (#6591)
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);
}