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

includes_value_test.ts
نووسراو ببینە
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-2022 the Deno authors. All rights reserved. MIT license.import { includesValue } from "./includes_value.ts";import { assert, assertEquals } from "../testing/asserts.ts";
Deno.test("[collections/includesValue] Example", () => { const input = { first: 33, second: 34, }; const actual = includesValue(input, 34); assert(actual);});
Deno.test("[collections/includesValue] No mutation", () => { const input = { first: 33, second: 34, };
includesValue(input, 34);
assertEquals(input, { first: 33, second: 34, });});
Deno.test("[collections/includesValue] Empty input returns false", () => { const input = {};
const actual = includesValue(input, 44);
assert(!actual);});
Deno.test("[collections/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("[collections/includesValue] 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("[collections/includesValue] Non-primitive values", () => { const input = { first: {}, };
const actual = includesValue(input, {});
assert(!actual);});
Deno.test("[collections/includesValue] 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("[collections/includesValue] Works with NaN", () => { const input = { first: NaN, };
const actual = includesValue(input, NaN);
assert(actual);});
Deno.test("[collections/includesValue] prevent 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
Deno standard library
GitHub Repositorydenoland/deno_std
GitHub Stars
2458

Version Info

Tagged at
2 months ago