Skip to content

Commit bced4fe

Browse files
committed
write tests for contains function
1 parent 0291dfa commit bced4fe

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

‎Sprint-2/implement/contains.test.js‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,23 @@ as the object doesn't contains a key of 'c'
1717
// When passed an object and a property name
1818
// Then it should return true if the object contains the property, false otherwise
1919

20+
describe("when checking property existence", () => {
21+
test("should return true if the object contains the property", () => {
22+
expect(contains({ a: "apple", b: "hill" }, "a")).toBe(true);
23+
});
24+
test("should return false if the object does not contain the property", () => {
25+
expect(contains({ a: "apple", b: "hill" }, "c")).toBe(false);
26+
});
27+
});
28+
2029
// Given an empty object
2130
// When passed to contains
2231
// Then it should return false
23-
test.todo("contains on empty object returns false");
32+
describe("given an empty object", () => {
33+
test("should return false when passed to contains", () => {
34+
expect(contains({}, "a").toBe(false));
35+
});
36+
});
2437

2538
// Given an object with properties
2639
// When passed to contains with an existing property name
@@ -33,3 +46,18 @@ test.todo("contains on empty object returns false");
3346
// Given invalid parameters like an array
3447
// When passed to contains
3548
// Then it should return false or throw an error
49+
describe("when given invalid inputs", () => {
50+
test("should throw an error if the input is not an object", () => {
51+
expect(() => contains([true, 2, "hill"], "2")).toThrow(
52+
"Input should be an object"
53+
);
54+
});
55+
56+
test("should throw an error if the input is not an object", () => {
57+
expect(() => contains(null, "hi")).toThrow("Input should be an object");
58+
});
59+
60+
test("should throw an error if the input is not an object", () => {
61+
expect(() => contains("apple", "a")).toThrow("Input should be an object");
62+
});
63+
});

0 commit comments

Comments
 (0)