Skip to content

Commit

Permalink
Add more tests of ObjectCanon prototype preservation.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Dec 16, 2020
1 parent f4f96c0 commit 2aa6af5
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/cache/inmemory/__tests__/object-canon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,38 @@ describe("ObjectCanon", () => {
check(2);

expect(canon.admit(customs)).toBe(admitted);

function checkProto(proto: null | object) {
const a = Object.create(proto);
const b = Object.create(proto, {
visible: {
value: "bee",
enumerable: true,
},
hidden: {
value: "invisibee",
enumerable: false,
},
});

const admitted = canon.admit({ a, b });

expect(admitted.a).toEqual(a);
expect(admitted.a).not.toBe(a);

expect(admitted.b).toEqual(b);
expect(admitted.b).not.toBe(b);

expect(Object.getPrototypeOf(admitted.a)).toBe(proto);
expect(Object.getPrototypeOf(admitted.b)).toBe(proto);

expect(admitted.b.visible).toBe("bee");
expect(admitted.b.hidden).toBeUndefined();
}
checkProto(null);
checkProto({});
checkProto([1,2,3]);
checkProto(() => "fun");
});

it("unwraps Pass wrappers as-is", () => {
Expand Down

0 comments on commit 2aa6af5

Please sign in to comment.