Skip to content

Commit

Permalink
Merge pull request #115 from jsr-core/test-is-required-of
Browse files Browse the repository at this point in the history
test[isRequiredOf]: add proper `true` or `false` cases
  • Loading branch information
lambdalisue authored Aug 11, 2024
2 parents 64ff84c + c84eb89 commit 255ee41
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions is/required_of_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,31 @@ Deno.test("isRequiredOf<T>", async (t) => {
});

await t.step("returns true on Required<T> object", () => {
assertEquals(isRequiredOf(pred)({ a: 0, b: "a", c: true, d: "a" }), true);
assertEquals(
isRequiredOf(pred)({ a: undefined, b: undefined, c: undefined }),
false,
"Object does not have required properties",
);
assertEquals(
isRequiredOf(pred)({}),
false,
"Object does not have required properties",
isRequiredOf(pred)({ a: 0, b: undefined, c: true, d: "a" }),
true,
"Union type contains 'undefined'",
);
});

await t.step("returns false on non Required<T> object", () => {
assertEquals(isRequiredOf(pred)("a"), false, "Value is not an object");
assertEquals(
isRequiredOf(pred)({ a: 0, b: "a", c: "" }),
isRequiredOf(pred)({ a: 0, b: "a", c: 0, d: "a" }),
false,
"Object have a different type property",
);
assertEquals(
isRequiredOf(pred)({ a: 0, b: "a", d: "a" }),
false,
"Object does not have required properties",
);
assertEquals(
isRequiredOf(pred)({ a: 0, b: "a", c: undefined, d: "a" }),
false,
"Optional property that converted to required is 'undefined'",
);
});

await t.step("predicated type is correct", () => {
Expand Down Expand Up @@ -69,24 +75,33 @@ Deno.test("isRequiredOf<T>", async (t) => {

await t.step("returns true on Required<T> object", () => {
assertEquals(
isRequiredOf(pred)({ a: undefined, [b]: undefined, [c]: undefined }),
false,
"Object does not have required properties",
isRequiredOf(pred)({ a: 0, [b]: "a", [c]: true, [d]: "a" }),
true,
);
assertEquals(
isRequiredOf(pred)({}),
false,
"Object does not have required properties",
isRequiredOf(pred)({ a: 0, [b]: undefined, [c]: true, [d]: "a" }),
true,
"Union type contains 'undefined'",
);
});

await t.step("returns false on non Required<T> object", () => {
assertEquals(isRequiredOf(pred)("a"), false, "Value is not an object");
assertEquals(
isRequiredOf(pred)({ a: 0, [b]: "a", [c]: "" }),
isRequiredOf(pred)({ a: 0, [b]: "a", [c]: 0, [d]: "a" }),
false,
"Object have a different type property",
);
assertEquals(
isRequiredOf(pred)({ a: 0, [b]: "a", [d]: "a" }),
false,
"Object does not have required properties",
);
assertEquals(
isRequiredOf(pred)({ a: 0, [b]: "a", [c]: undefined, [d]: "a" }),
false,
"Optional property that converted to required is 'undefined'",
);
});

await t.step("predicated type is correct", () => {
Expand Down

0 comments on commit 255ee41

Please sign in to comment.