diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2020-06-03 04:38:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-02 23:38:46 -0400 |
commit | aaa2ed5a6450572d90fdb3fc2f0000759599d46f (patch) | |
tree | 06f5e07e8042156655d42996d5e7e677f62eefe3 /std/testing/asserts.ts | |
parent | 1db98f10b804129d965daa18de6d528e592a3c0f (diff) |
fix(std/testing/asserts): Format values in assertArrayContains() (#6060)
Diffstat (limited to 'std/testing/asserts.ts')
-rw-r--r-- | std/testing/asserts.ts | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/std/testing/asserts.ts b/std/testing/asserts.ts index ce7214998..18cf9134e 100644 --- a/std/testing/asserts.ts +++ b/std/testing/asserts.ts @@ -2,7 +2,7 @@ /** 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 { red, green, white, gray, bold, stripColor } from "../fmt/colors.ts"; import diff, { DiffType, DiffResult } from "./diff.ts"; const CAN_NOT_DISPLAY = "[Cannot display]"; @@ -289,9 +289,9 @@ export function assertArrayContains( return; } if (!msg) { - msg = `actual: "${actual}" expected to contain: "${expected}"`; - msg += "\n"; - msg += `missing: ${missing}`; + msg = `actual: "${format(actual)}" expected to contain: "${format( + expected + )}"\nmissing: ${format(missing)}`; } throw new AssertionError(msg); } @@ -342,7 +342,10 @@ export function assertThrows( }"${msg ? `: ${msg}` : "."}`; throw new AssertionError(msg); } - if (msgIncludes && !e.message.includes(msgIncludes)) { + if ( + msgIncludes && + !stripColor(e.message).includes(stripColor(msgIncludes)) + ) { msg = `Expected error message to include "${msgIncludes}", but got "${ e.message }"${msg ? `: ${msg}` : "."}`; @@ -375,7 +378,10 @@ export async function assertThrowsAsync( }"${msg ? `: ${msg}` : "."}`; throw new AssertionError(msg); } - if (msgIncludes && !e.message.includes(msgIncludes)) { + if ( + msgIncludes && + !stripColor(e.message).includes(stripColor(msgIncludes)) + ) { msg = `Expected error message to include "${msgIncludes}", but got "${ e.message }"${msg ? `: ${msg}` : "."}`; |