Skip to content

Commit dd5a43c

Browse files
committed
Refactor contains tests to include cases for empty objects and invalid parameters
1 parent 391bd80 commit dd5a43c

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,34 @@ as the object doesn't contains a key of 'c'
2020
// Given an empty object
2121
// When passed to contains
2222
// Then it should return false
23-
test.todo("contains on empty object returns false");
23+
24+
describe("contains()", () => {
25+
test("returns false when given an empty object", () => {
26+
expect(contains({}, "a")).toBe(false);
27+
});
2428

2529
// Given an object with properties
2630
// When passed to contains with an existing property name
2731
// Then it should return true
2832

33+
test("returns true when the object contains the property name", () => {
34+
expect(contains({ a: 1, b: 2 }, "a")).toBe(true);
35+
2936
// Given an object with properties
3037
// When passed to contains with a non-existent property name
3138
// Then it should return false
3239

40+
test("returns false when the object does not contain the property name", () => {
41+
expect(contains({ a: 1, b: 2 }, "c")).toBe(false);
42+
});
43+
3344
// Given invalid parameters like an array
3445
// When passed to contains
3546
// Then it should return false or throw an error
47+
48+
test("returns false when passed invalid parameters like an array or primitive", () => {
49+
expect(contains(["a", "b"], "0")).toBe(false);
50+
expect(contains(null, "a")).toBe(false);
51+
expect(contains("string", "length")).toBe(false);
52+
});
53+
});

0 commit comments

Comments
 (0)