1
0
Fork 0
functional/objects.test.ts

32 lines
990 B
TypeScript

import { expect, it } from "./deps.testing.ts";
import { attr, defined, options } from "./objects.ts";
it("attr", () => {
const getx = attr("x");
expect(getx({ x: 4, y: 5 })).toBe(4);
expect(getx({ x: undefined, y: 5 })).toBeUndefined();
});
it("defined", () => {
expect(defined({})).toEqual({});
expect(defined({ x: 1 })).toEqual({ x: 1 });
expect(defined({ x: 1, y: undefined })).toEqual({ x: 1 });
const obj = defined({ x: 1, y: undefined });
// @ts-expect-error
expect(obj.y).toBeUndefined();
});
it("options", () => {
expect(options({})).toEqual({});
expect(options({ x: 1, y: 2 }, { x: 3 })).toEqual({ x: 3, y: 2 });
expect(options({ x: 1, y: 2 }, { x: 3 }, { x: 4 })).toEqual({ x: 4, y: 2 });
expect(options({ x: 1, y: 2 }, { x: 3 }, { y: 0 })).toEqual({ x: 3, y: 0 });
expect(options({ x: 1, y: 2 }, { x: undefined, y: 3 })).toEqual({
x: 1,
y: 3,
});
// @ts-expect-error
expect(options({ x: 1 }, { y: 2 })).toEqual({ x: 1, y: 2 });
});