Browse Source

feat: add tests

pull/18/head
Máté Szentgróti 11 months ago
parent
commit
ba53693ee2
  1. 82
      test/object-diff.test.ts
  2. 2
      test/utils.test.ts

82
test/object-diff.test.ts

@ -858,4 +858,86 @@ describe("getObjectDiff", () => { @@ -858,4 +858,86 @@ describe("getObjectDiff", () => {
],
});
});
it("detects changes when comparing an array value property to a non-array value property", () => {
expect(
getObjectDiff(
{
name: "joe",
age: 55,
hobbies: ["golf", "football"]
},
{
name: "joe",
age: 55,
hobbies: null
}))
.toStrictEqual({
type: "object",
status: "updated",
diff: [
{
currentValue: "joe",
previousValue: "joe",
property: "name",
status: "equal",
},
{
currentValue: 55,
previousValue: 55,
property: "age",
status: "equal",
},
{
currentValue: null,
previousValue: [
"golf",
"football",
],
property: "hobbies",
status: "updated",
}
]
})
})
it("detects changes when comparing a non-array value property to an array value property", () => {
expect(
getObjectDiff(
{
name: "joe",
age: 55,
hobbies: null
},
{
name: "joe",
age: 55,
hobbies: ["golf", "football"]
}))
.toStrictEqual({
type: "object",
status: "updated",
diff: [
{
currentValue: "joe",
previousValue: "joe",
property: "name",
status: "equal",
},
{
currentValue: 55,
previousValue: 55,
property: "age",
status: "equal",
},
{
currentValue: [
"golf",
"football",
],
previousValue: null,
property: "hobbies",
status: "updated",
}
]
})
});
});

2
test/utils.test.ts

@ -39,6 +39,8 @@ describe("isEqual", () => { @@ -39,6 +39,8 @@ describe("isEqual", () => {
)
).toBeFalsy();
expect(isEqual(["psg"], ["psg", "nantes"])).toBeFalsy();
expect(isEqual(null, ["hello", "world"])).toBeFalsy();
expect(isEqual(["hello", "world"], null)).toBeFalsy();
});
it("return true if ignoreArrayOrder option is activated and arrays contains the same values regardless of their positions", () => {
expect(

Loading…
Cancel
Save