2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-07-13 07:04:30 +00:00
|
|
|
import { assertArrayIncludes, AssertionError, assertThrows } from "./mod.ts";
|
|
|
|
|
2023-12-08 16:04:29 +00:00
|
|
|
const fixture = ["deno", "iz", "luv"];
|
|
|
|
const fixtureObject = [{ deno: "luv" }, { deno: "Js" }];
|
2023-12-08 08:04:06 +00:00
|
|
|
|
2023-12-08 16:04:29 +00:00
|
|
|
Deno.test("assertArrayIncludes() matches when array includes value", () => {
|
|
|
|
assertArrayIncludes(fixture, ["deno"]);
|
|
|
|
assertArrayIncludes(fixtureObject, [{ deno: "luv" }]);
|
|
|
|
assertArrayIncludes(
|
|
|
|
Uint8Array.from([1, 2, 3, 4]),
|
|
|
|
Uint8Array.from([1, 2, 3]),
|
|
|
|
);
|
|
|
|
assertArrayIncludes(["a"], ["a"]);
|
|
|
|
assertArrayIncludes(["a", "b", "c"], ["a", "b"]);
|
|
|
|
});
|
2023-12-08 08:04:06 +00:00
|
|
|
|
2023-12-08 16:04:29 +00:00
|
|
|
Deno.test("assertArrayIncludes() throws when array is missing value", () => {
|
|
|
|
assertThrows(
|
|
|
|
() => assertArrayIncludes(["a"], ["b"]),
|
|
|
|
AssertionError,
|
|
|
|
`
|
2023-12-08 08:04:06 +00:00
|
|
|
Expected actual: "[
|
|
|
|
"a",
|
|
|
|
]" to include: "[
|
|
|
|
"b",
|
|
|
|
]".
|
|
|
|
missing: [
|
|
|
|
"b",
|
|
|
|
]
|
|
|
|
`.trim(),
|
2023-12-08 16:04:29 +00:00
|
|
|
);
|
2023-12-08 08:04:06 +00:00
|
|
|
|
2023-12-08 16:04:29 +00:00
|
|
|
assertThrows(
|
|
|
|
() => assertArrayIncludes(fixtureObject, [{ deno: "node" }]),
|
|
|
|
AssertionError,
|
|
|
|
`
|
2023-12-08 08:04:06 +00:00
|
|
|
Expected actual: "[
|
2023-07-13 07:04:30 +00:00
|
|
|
{
|
|
|
|
deno: "luv",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
deno: "Js",
|
|
|
|
},
|
|
|
|
]" to include: "[
|
|
|
|
{
|
|
|
|
deno: "node",
|
|
|
|
},
|
|
|
|
]".
|
|
|
|
missing: [
|
|
|
|
{
|
|
|
|
deno: "node",
|
|
|
|
},
|
2023-12-08 08:04:06 +00:00
|
|
|
]
|
|
|
|
`.trim(),
|
2023-12-08 16:04:29 +00:00
|
|
|
);
|
|
|
|
});
|
2023-12-08 08:04:06 +00:00
|
|
|
|
2024-05-07 00:08:16 +00:00
|
|
|
Deno.test("assertArrayIncludes() throws with custom message", () => {
|
|
|
|
assertThrows(
|
|
|
|
() => assertArrayIncludes(["a"], ["b"], "CUSTOM MESSAGE"),
|
|
|
|
AssertionError,
|
|
|
|
`
|
|
|
|
Expected actual: "[
|
|
|
|
"a",
|
|
|
|
]" to include: "[
|
|
|
|
"b",
|
|
|
|
]": CUSTOM MESSAGE
|
|
|
|
missing: [
|
|
|
|
"b",
|
|
|
|
]
|
|
|
|
`.trim(),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2023-12-08 16:04:29 +00:00
|
|
|
// https://github.com/denoland/deno_std/issues/3372
|
|
|
|
Deno.test("assertArrayIncludes() type-checks failing cases", () => {
|
|
|
|
// @ts-expect-error 2nd arg - 'string' is not assignable to 'ArrayLikeArg<string>'.
|
|
|
|
assertThrows(() => assertArrayIncludes(["a"], "b"));
|
|
|
|
// @ts-expect-error 1st arg - 'string' is not assignable to 'ArrayLikeArg<string>'.
|
|
|
|
assertThrows(() => assertArrayIncludes("a", ["b"]));
|
|
|
|
// @ts-expect-error both args - 'string' is not assignable to 'ArrayLikeArg<string>'.
|
|
|
|
assertThrows(() => assertArrayIncludes("a", "b"));
|
2023-07-13 07:04:30 +00:00
|
|
|
});
|