deno.land / std@0.224.0 / collections / includes_value_test.ts

includes_value_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.import { includesValue } from "./includes_value.ts";import { assert, assertEquals } from "../assert/mod.ts";
Deno.test("includesValue() handles example", () => { const input = { first: 33, second: 34, }; const actual = includesValue(input, 34); assert(actual);});
Deno.test("includesValue() handles no mutation", () => { const input = { first: 33, second: 34, };
includesValue(input, 34);
assertEquals(input, { first: 33, second: 34, });});
Deno.test("includesValue() handles empty input returns false", () => { const input = {};
const actual = includesValue(input, 44);
assert(!actual);});
Deno.test("includesValue() returns false when it doesn't include the value", () => { const input = { first: 33, second: 34, };
const actual = includesValue(input, 45);
assert(!actual);});
Deno.test("includesValue() handles non-enumerable properties", () => { // FAIL is expected, TODO: Figure out how to make it work on const input = {};
Object.defineProperty(input, "nep", { enumerable: false, value: 42, });
Object.defineProperty(input, "neptwo", { enumerable: false, value: "hello", });
Object.defineProperty(input, "nepthree", { enumerable: false, value: true, });
const actual1 = includesValue(input, 42); const actual2 = includesValue(input, "hello"); const actual3 = includesValue(input, true);
assert(!actual1); assert(!actual2); assert(!actual3);});
Deno.test("includesValue() handles non-primitive values", () => { const input = { first: {}, };
const actual = includesValue(input, {});
assert(!actual);});
Deno.test("includesValue() handles same behaviour as naive impl", () => { const input = { first: 42, };
const includesValueResult = includesValue(input, 42); const naiveImplResult = Object.values(input).includes(42);
assertEquals(includesValueResult, naiveImplResult);});
Deno.test("includesValue() handles NaN value", () => { const input = { first: NaN, };
const actual = includesValue(input, NaN);
assert(actual);});
Deno.test("includesValue() prevents enumerable prototype check", () => { class Foo {} // @ts-ignore: for test Foo.prototype.a = "hello"; const input = new Foo() as Record<string, string>;
const actual = includesValue(input, "hello");
assert(!actual);});
std

Version Info

Tagged at
6 months ago