-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject_has_properties.test.ts
More file actions
93 lines (85 loc) · 2.26 KB
/
object_has_properties.test.ts
File metadata and controls
93 lines (85 loc) · 2.26 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
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
import { assert, assertFalse, AssertionError, assertThrows } from "@std/assert";
import {
assertObjectHasProperties,
assertObjectHasPropertiesDeep,
objectHasProperties,
objectHasPropertiesDeep,
} from "./object_has_properties.ts";
const VALID: Array<[object, Array<PropertyKey>]> = [
[{ [Symbol.for("test")]: 0 }, [Symbol.for("test")]],
[{ 1: 0 }, [1]],
[{ 0: 0 }, [0]],
[{ "": 0 }, [""]],
[{ "test": 0 }, ["test"]],
];
const INVALID: Array<[object, Array<PropertyKey>]> = [
[{}, [Symbol.for("test")]],
[{ [Symbol.for("test2")]: 0 }, [Symbol.for("test")]],
[{}, [1]],
[{}, [""]],
[{}, ["test"]],
];
class NestedClass extends (class {
get test() {
return "test";
}
}) {}
const nestedClass = new NestedClass();
const INVALID_NOT_DEEP: Array<[object, Array<PropertyKey>]> = [
...INVALID,
[nestedClass, ["test"]],
];
const VALID_DEEP: Array<[object, Array<PropertyKey>]> = [
...VALID,
[nestedClass, ["test"]],
];
Deno.test("objectHasProperties > can detect all property keys", () => {
for (const v of VALID) {
assert(
objectHasProperties(v[0], v[1]),
`Value of '${JSON.stringify(v)}' is not valid`,
);
}
for (const v of INVALID_NOT_DEEP) {
assertFalse(
objectHasProperties(v[0], v[1]),
`Value of '${JSON.stringify(v)}' is not invalid`,
);
}
});
Deno.test("assertObjectHasProperties > can detect all property keys", () => {
for (const v of VALID) {
assertObjectHasProperties(v[0], v[1]);
}
for (const v of INVALID) {
assertThrows(
() => assertObjectHasProperties(v[0], v[1]),
AssertionError,
);
}
});
Deno.test("objectHasPropertiesDeep > can detect all property keys", () => {
for (const v of VALID_DEEP) {
assert(
objectHasPropertiesDeep(v[0], v[1]),
`Value of '${JSON.stringify(v)}' is not valid`,
);
}
for (const v of INVALID) {
assertFalse(
objectHasPropertiesDeep(v[0], v[1]),
`Value of '${JSON.stringify(v)}' is not invalid`,
);
}
});
Deno.test("assertObjectHasPropertiesDeep > can detect all property keys", () => {
for (const v of VALID) {
assertObjectHasPropertiesDeep(v[0], v[1]);
}
for (const v of INVALID) {
assertThrows(
() => assertObjectHasPropertiesDeep(v[0], v[1]),
AssertionError,
);
}
});