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.ts9
1 files changed, 6 insertions, 3 deletions
diff --git a/std/testing/asserts.ts b/std/testing/asserts.ts
index d3f8bb678..ce7214998 100644
--- a/std/testing/asserts.ts
+++ b/std/testing/asserts.ts
@@ -1,4 +1,7 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+/** This module is browser compatible. Do not rely on good formatting of values
+ * for AssertionError messages in browsers. */
+
import { red, green, white, gray, bold } from "../fmt/colors.ts";
import diff, { DiffType, DiffResult } from "./diff.ts";
@@ -17,7 +20,7 @@ export class AssertionError extends Error {
}
function format(v: unknown): string {
- let string = Deno.inspect(v);
+ let string = globalThis.Deno ? Deno.inspect(v) : String(v);
if (typeof v == "string") {
string = `"${string.replace(/(?=["\\])/g, "\\")}"`;
}
@@ -254,7 +257,7 @@ export function assertStrContains(
): void {
if (!actual.includes(expected)) {
if (!msg) {
- msg = `actual: "${actual}" expected to contains: "${expected}"`;
+ msg = `actual: "${actual}" expected to contain: "${expected}"`;
}
throw new AssertionError(msg);
}
@@ -286,7 +289,7 @@ export function assertArrayContains(
return;
}
if (!msg) {
- msg = `actual: "${actual}" expected to contains: "${expected}"`;
+ msg = `actual: "${actual}" expected to contain: "${expected}"`;
msg += "\n";
msg += `missing: ${missing}`;
}