Skip to content

Commit

Permalink
tests: isSimpleEqual, update compareMergeChanges #190
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenesius committed Dec 9, 2023
1 parent 5958f94 commit 5a9255d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/units/form/form-read-save.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe("Form read/save", () => {
await wait();
expect(form.wait).toBe(true);

await wait(60);
await wait(10);
expect(form.wait).toBe(true);

await promise;
Expand Down
18 changes: 18 additions & 0 deletions tests/units/utils/compare-merge-changes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,22 @@ describe("find changes", () => {

])
});

test("test", () => {
const source = {
age: 1,
name: "Jack",
application: {
name: "AA-1",
customers: {},
environments: {}
}
};
const changes = {
name: "Jen-esius"
};

expect(compareMergeChanges(source, changes)).toHaveLength(1);
expect(compareMergeChanges(source, changes)).toEqual([{ name: "name", newValue: "Jen-esius", oldValue: 'Jack' },])
})
})
21 changes: 21 additions & 0 deletions tests/units/utils/is-simple-equal.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import isSimpleEqual from "../../../src/utils/is-simple-equal";

describe("Testing is simple equal", () => {
test("Basic values", () => {
expect(isSimpleEqual(1, 0)).toEqual(false)
expect(isSimpleEqual(1, "2")).toEqual(false)
expect(isSimpleEqual(1, "1")).toEqual(false)
expect(isSimpleEqual(0, false)).toEqual(false)
expect(isSimpleEqual(true, 1)).toEqual(false)
expect(isSimpleEqual({}, false)).toEqual(false)
expect(isSimpleEqual({}, [])).toEqual(false)
expect(isSimpleEqual(NaN, null)).toEqual(false)
})
test("Empty object and array should be equal", () => {
expect(isSimpleEqual({}, {})).toEqual(true)
expect(isSimpleEqual([], [])).toEqual(true)
})
test("Deep object should not be equal", () => {
expect(isSimpleEqual({a: 1}, {a: 1})).toEqual(false);
})
})

0 comments on commit 5a9255d

Please sign in to comment.