deno.land / std@0.224.0 / assert / assert_array_includes_test.ts

assert_array_includes_test.ts
View Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.import { assertArrayIncludes, AssertionError, assertThrows } from "./mod.ts";
const fixture = ["deno", "iz", "luv"];const fixtureObject = [{ deno: "luv" }, { deno: "Js" }];
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"]);});
Deno.test("assertArrayIncludes() throws when array is missing value", () => { assertThrows( () => assertArrayIncludes(["a"], ["b"]), AssertionError, `Expected actual: "[ "a",]" to include: "[ "b",]".missing: [ "b",]`.trim(), );
assertThrows( () => assertArrayIncludes(fixtureObject, [{ deno: "node" }]), AssertionError, `Expected actual: "[ { deno: "luv", }, { deno: "Js", },]" to include: "[ { deno: "node", },]".missing: [ { deno: "node", },]`.trim(), );});
// https://github.com/denoland/deno_std/issues/3372Deno.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"));});
std

Version Info

Tagged at
6 months ago