mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
fix(std/testing/asserts): Format values in assertArrayContains() (#6060)
This commit is contained in:
parent
1db98f10b8
commit
aaa2ed5a64
2 changed files with 17 additions and 15 deletions
|
@ -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}` : "."}`;
|
||||
|
|
|
@ -151,15 +151,11 @@ test("testingArrayContains", function (): void {
|
|||
const fixtureObject = [{ deno: "luv" }, { deno: "Js" }];
|
||||
assertArrayContains(fixture, ["deno"]);
|
||||
assertArrayContains(fixtureObject, [{ deno: "luv" }]);
|
||||
let didThrow;
|
||||
try {
|
||||
assertArrayContains(fixtureObject, [{ deno: "node" }]);
|
||||
didThrow = false;
|
||||
} catch (e) {
|
||||
assert(e instanceof AssertionError);
|
||||
didThrow = true;
|
||||
}
|
||||
assertEquals(didThrow, true);
|
||||
assertThrows(
|
||||
(): void => assertArrayContains(fixtureObject, [{ deno: "node" }]),
|
||||
AssertionError,
|
||||
`actual: "[ { deno: "luv" }, { deno: "Js" } ]" expected to contain: "[ { deno: "node" } ]"\nmissing: [ { deno: "node" } ]`
|
||||
);
|
||||
});
|
||||
|
||||
test("testingAssertStringContainsThrow", function (): void {
|
||||
|
|
Loading…
Reference in a new issue