-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathassociate-array.test.ts
More file actions
44 lines (37 loc) · 1.33 KB
/
associate-array.test.ts
File metadata and controls
44 lines (37 loc) · 1.33 KB
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
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
import * as assert from "@std/assert";
import { associateArray } from "./associate-array.ts";
Deno.test("basic", () => {
const arr1 = [
{ id: 1, name: "foo" },
{ id: 2, name: "bar" },
{ id: 3, name: "baz" },
];
const func1 = (value: { id: number; name: string }) => value.id;
const result = associateArray(arr1, func1);
// deno-lint-ignore no-explicit-any
assert.assertNotStrictEquals(<any> result, <any> arr1);
assert.assertEquals(Object.keys(result).length, 3);
assert.assertEquals(result, {
1: { id: 1, name: "foo" },
2: { id: 2, name: "bar" },
3: { id: 3, name: "baz" },
});
});
Deno.test("with-value-skipping", () => {
const arr1 = [
{ id: 1, name: "foo", skip: false },
{ id: 2, name: "bar", skip: false },
{ id: 3, name: "baz", skip: true },
];
const func1 = (value: { id: number; name: string; skip: boolean }) =>
value.skip ? undefined : value.id;
const result = associateArray(arr1, func1);
// deno-lint-ignore no-explicit-any
assert.assertNotStrictEquals(<any> result, <any> arr1);
assert.assertEquals(Object.keys(result).length, 2);
assert.assertEquals(result, {
1: { id: 1, name: "foo", skip: false },
2: { id: 2, name: "bar", skip: false },
});
});