2021-08-26 23:01:08 +00:00
|
|
|
import { expect, it } from "./deps.testing.ts";
|
|
|
|
import { attr, defined, options } from "./objects.ts";
|
2020-05-11 22:34:57 +00:00
|
|
|
|
2020-12-02 20:58:26 +00:00
|
|
|
it("attr", () => {
|
2020-05-11 22:34:57 +00:00
|
|
|
const getx = attr("x");
|
2020-05-13 09:46:10 +00:00
|
|
|
expect(getx({ x: 4, y: 5 })).toBe(4);
|
|
|
|
expect(getx({ x: undefined, y: 5 })).toBeUndefined();
|
2020-05-11 22:34:57 +00:00
|
|
|
});
|
2021-08-26 23:01:08 +00:00
|
|
|
|
|
|
|
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 });
|
|
|
|
});
|