diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2020-05-25 18:32:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-25 13:32:34 -0400 |
commit | 4ebd24342368adbb99582b87dc6c4b8cb6f44c87 (patch) | |
tree | 0e98b22c00497d48ea901bc24bad8fe182fdd056 /std/testing/asserts.ts | |
parent | 08f74e1f6a180e83e13f5570811b8b7fcec90e9f (diff) |
fix(std/testing/asserts): Support browsers (#5847)
Diffstat (limited to 'std/testing/asserts.ts')
-rw-r--r-- | std/testing/asserts.ts | 9 |
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}`; } |