2021-08-02 08:47:49 +02:00
|
|
|
import assert from "assert";
|
|
|
|
|
|
|
|
import { partialDeepEquals } from "../utils";
|
|
|
|
|
|
|
|
describe("Test utils ", () => {
|
|
|
|
it("objectContain", async () => {
|
|
|
|
assert(partialDeepEquals(
|
|
|
|
{
|
|
|
|
name: "John Wick",
|
|
|
|
old: 20,
|
|
|
|
vip: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
2021-08-11 05:13:56 +02:00
|
|
|
},
|
|
|
|
false
|
2021-08-02 08:47:49 +02:00
|
|
|
), "Did not match empty expect");
|
|
|
|
assert(partialDeepEquals(
|
|
|
|
[{a: [1,2,3]}, {a: [1,2]}],
|
|
|
|
[{a: [1,2,3]}, {a: [1,2]}]
|
|
|
|
), "Did not match same arrays");
|
|
|
|
assert(partialDeepEquals(
|
|
|
|
{
|
|
|
|
name: "John Wick",
|
|
|
|
old: 20,
|
|
|
|
vip: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
vip: true,
|
|
|
|
old: 20
|
|
|
|
}
|
|
|
|
), "Did not match same partial properties");
|
|
|
|
// do not match incorrect propeties
|
|
|
|
assert(!partialDeepEquals(
|
|
|
|
{
|
|
|
|
name: "John Wick",
|
|
|
|
old: 20,
|
|
|
|
vip: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
vip: false,
|
|
|
|
old: 19
|
2021-08-11 05:13:56 +02:00
|
|
|
},
|
|
|
|
false
|
2021-08-02 08:47:49 +02:00
|
|
|
), "Matched different properties");
|
|
|
|
// do not match missing property
|
|
|
|
assert(!partialDeepEquals(
|
|
|
|
{
|
|
|
|
name: "John Wick",
|
|
|
|
old: 20,
|
|
|
|
vip: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
vip: true,
|
|
|
|
child: {
|
|
|
|
name: ""
|
|
|
|
}
|
2021-08-11 05:13:56 +02:00
|
|
|
},
|
|
|
|
false
|
2021-08-02 08:47:49 +02:00
|
|
|
));
|
|
|
|
assert(!partialDeepEquals(
|
|
|
|
{
|
|
|
|
name: "John Wick",
|
|
|
|
old: 20,
|
|
|
|
vip: true,
|
|
|
|
child: {
|
|
|
|
name: "a"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
vip: true,
|
|
|
|
child: {
|
|
|
|
name: ""
|
|
|
|
}
|
2021-08-11 05:13:56 +02:00
|
|
|
},
|
|
|
|
false
|
2021-08-02 08:47:49 +02:00
|
|
|
), "Matched incorrect child property");
|
|
|
|
assert(!partialDeepEquals(
|
|
|
|
{
|
|
|
|
name: "John Wick",
|
|
|
|
old: 20,
|
|
|
|
vip: true,
|
|
|
|
child: {
|
|
|
|
name: "a",
|
|
|
|
child: {
|
|
|
|
name: "a",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
vip: true,
|
|
|
|
child: {
|
|
|
|
name: "a",
|
|
|
|
child: {
|
|
|
|
name: "b",
|
|
|
|
}
|
|
|
|
}
|
2021-08-11 05:13:56 +02:00
|
|
|
},
|
|
|
|
false
|
2021-08-02 08:47:49 +02:00
|
|
|
), "Matched incorrected 2-nested property");
|
|
|
|
assert(partialDeepEquals(
|
|
|
|
{
|
|
|
|
name: "John Wick",
|
|
|
|
old: 20,
|
|
|
|
vip: true,
|
|
|
|
child: {
|
|
|
|
name: "a",
|
|
|
|
child: {
|
|
|
|
name: "b",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
vip: true,
|
|
|
|
child: {
|
|
|
|
name: "a",
|
|
|
|
child: {
|
|
|
|
name: "b",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
), "Did not match exact child properties");
|
|
|
|
assert(partialDeepEquals(
|
|
|
|
{
|
|
|
|
name: "John Wick",
|
|
|
|
values: [{
|
|
|
|
name: "a",
|
|
|
|
}, {
|
|
|
|
name: "b",
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
values: [{
|
|
|
|
name: "a",
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
), "Did not match partial child array");
|
|
|
|
});
|
|
|
|
});
|