-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathpoints.test.ts
More file actions
31 lines (27 loc) · 949 Bytes
/
points.test.ts
File metadata and controls
31 lines (27 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { isValidPoint } from "./points";
describe("isValidPoint", () => {
it("accepts objects with required own properties", () => {
expect(
isValidPoint({
badge: null,
condition: "",
content: "",
})
).toBe(true);
});
it("rejects primitives and null", () => {
expect(isValidPoint(null)).toBe(false);
expect(isValidPoint(undefined)).toBe(false);
expect(isValidPoint("x")).toBe(false);
});
it("rejects objects missing a required key", () => {
expect(isValidPoint({ badge: 1, condition: "" })).toBe(false);
expect(isValidPoint({ badge: 1, content: "" })).toBe(false);
expect(isValidPoint({ condition: "", content: "" })).toBe(false);
});
it("rejects objects that only inherit required keys from the prototype", () => {
const proto = { badge: 1, condition: "", content: "" };
const o = Object.create(proto);
expect(isValidPoint(o)).toBe(false);
});
});