Skip to content

Commit

Permalink
test[isObjectOf]: clarify target var name and assertion messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Milly committed Aug 8, 2024
1 parent e01ab01 commit 0ec8074
Showing 1 changed file with 51 additions and 39 deletions.
90 changes: 51 additions & 39 deletions is/object_of_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ Deno.test("isObjectOf<T>", async (t) => {
assertEquals(
isObjectOf(predObj)({ a: 0, b: "a", c: true, d: "ignored" }),
true,
"Undefined properties are ignored",
);
assertEquals(
isObjectOf(predObj)(
Object.assign(() => void 0, { a: 0, b: "a", c: true }),
),
true,
"Function are treated as an object",
);
});

Expand Down Expand Up @@ -99,45 +101,55 @@ Deno.test("isObjectOf<T>", async (t) => {
}
});

await t.step("if 'predObj' has prototype properties", async (t) => {
const prototypeObj = {
a: is.Number,
b: is.Boolean,
};
// deno-lint-ignore ban-types
const predObj2 = Object.assign(Object.create(prototypeObj) as {}, {
c: is.String,
});
await t.step(
"does not affect prototype properties of 'predObj'",
async (t) => {
const prototypeObj = {
a: is.Number,
b: is.Boolean,
};
// deno-lint-ignore ban-types
const predObj = Object.assign(Object.create(prototypeObj) as {}, {
c: is.String,
});

await t.step("returns true on T object that omits prototype", () => {
assertEquals(isObjectOf(predObj2)({ c: "a" }), true);
assertEquals(
isObjectOf(predObj2)({ c: "a", d: "ignored" }),
true,
);
assertEquals(
isObjectOf(predObj2)(Object.assign(() => void 0, { c: "a" })),
true,
);
});
await t.step("returns true on T object", () => {
assertEquals(isObjectOf(predObj)({ c: "a" }), true);
assertEquals(
isObjectOf(predObj)({ a: "ignored", b: "ignored", c: "a" }),
true,
"Predicates defined in the prototype are ignored",
);
assertEquals(
isObjectOf(predObj)({ c: "a", d: "ignored" }),
true,
"Undefined properties are ignored",
);
assertEquals(
isObjectOf(predObj)(Object.assign(() => void 0, { c: "a" })),
true,
"Function are treated as an object",
);
});

await t.step("returns false on non T object that omits prototype", () => {
assertEquals(isObjectOf(predObj2)("a"), false, "Value is not an object");
assertEquals(
isObjectOf(predObj2)({ a: 0, b: true, c: 1 }),
false,
"Object have a different type property",
);
assertEquals(
isObjectOf(predObj2)({ a: 0, b: true }),
false,
"Object does not have one property",
);
assertEquals(
isObjectOf({ 0: is.String })(["a"]),
false,
"Value is not an object",
);
});
});
await t.step("returns false on non T object", () => {
assertEquals(isObjectOf(predObj)("a"), false, "Value is not an object");
assertEquals(
isObjectOf(predObj)({ a: 0, b: true, c: 1 }),
false,
"Object have a different type property",
);
assertEquals(
isObjectOf(predObj)({ a: 0, b: true }),
false,
"Object does not have one property",
);
assertEquals(
isObjectOf({ 0: is.String })(["a"]),
false,
"Value is not an object",
);
});
},
);
});

0 comments on commit 0ec8074

Please sign in to comment.