Skip to content

Commit 0ec8074

Browse files
committed
test[isObjectOf]: clarify target var name and assertion messages
1 parent e01ab01 commit 0ec8074

File tree

1 file changed

+51
-39
lines changed

1 file changed

+51
-39
lines changed

is/object_of_test.ts

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ Deno.test("isObjectOf<T>", async (t) => {
3131
assertEquals(
3232
isObjectOf(predObj)({ a: 0, b: "a", c: true, d: "ignored" }),
3333
true,
34+
"Undefined properties are ignored",
3435
);
3536
assertEquals(
3637
isObjectOf(predObj)(
3738
Object.assign(() => void 0, { a: 0, b: "a", c: true }),
3839
),
3940
true,
41+
"Function are treated as an object",
4042
);
4143
});
4244

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

102-
await t.step("if 'predObj' has prototype properties", async (t) => {
103-
const prototypeObj = {
104-
a: is.Number,
105-
b: is.Boolean,
106-
};
107-
// deno-lint-ignore ban-types
108-
const predObj2 = Object.assign(Object.create(prototypeObj) as {}, {
109-
c: is.String,
110-
});
104+
await t.step(
105+
"does not affect prototype properties of 'predObj'",
106+
async (t) => {
107+
const prototypeObj = {
108+
a: is.Number,
109+
b: is.Boolean,
110+
};
111+
// deno-lint-ignore ban-types
112+
const predObj = Object.assign(Object.create(prototypeObj) as {}, {
113+
c: is.String,
114+
});
111115

112-
await t.step("returns true on T object that omits prototype", () => {
113-
assertEquals(isObjectOf(predObj2)({ c: "a" }), true);
114-
assertEquals(
115-
isObjectOf(predObj2)({ c: "a", d: "ignored" }),
116-
true,
117-
);
118-
assertEquals(
119-
isObjectOf(predObj2)(Object.assign(() => void 0, { c: "a" })),
120-
true,
121-
);
122-
});
116+
await t.step("returns true on T object", () => {
117+
assertEquals(isObjectOf(predObj)({ c: "a" }), true);
118+
assertEquals(
119+
isObjectOf(predObj)({ a: "ignored", b: "ignored", c: "a" }),
120+
true,
121+
"Predicates defined in the prototype are ignored",
122+
);
123+
assertEquals(
124+
isObjectOf(predObj)({ c: "a", d: "ignored" }),
125+
true,
126+
"Undefined properties are ignored",
127+
);
128+
assertEquals(
129+
isObjectOf(predObj)(Object.assign(() => void 0, { c: "a" })),
130+
true,
131+
"Function are treated as an object",
132+
);
133+
});
123134

124-
await t.step("returns false on non T object that omits prototype", () => {
125-
assertEquals(isObjectOf(predObj2)("a"), false, "Value is not an object");
126-
assertEquals(
127-
isObjectOf(predObj2)({ a: 0, b: true, c: 1 }),
128-
false,
129-
"Object have a different type property",
130-
);
131-
assertEquals(
132-
isObjectOf(predObj2)({ a: 0, b: true }),
133-
false,
134-
"Object does not have one property",
135-
);
136-
assertEquals(
137-
isObjectOf({ 0: is.String })(["a"]),
138-
false,
139-
"Value is not an object",
140-
);
141-
});
142-
});
135+
await t.step("returns false on non T object", () => {
136+
assertEquals(isObjectOf(predObj)("a"), false, "Value is not an object");
137+
assertEquals(
138+
isObjectOf(predObj)({ a: 0, b: true, c: 1 }),
139+
false,
140+
"Object have a different type property",
141+
);
142+
assertEquals(
143+
isObjectOf(predObj)({ a: 0, b: true }),
144+
false,
145+
"Object does not have one property",
146+
);
147+
assertEquals(
148+
isObjectOf({ 0: is.String })(["a"]),
149+
false,
150+
"Value is not an object",
151+
);
152+
});
153+
},
154+
);
143155
});

0 commit comments

Comments
 (0)