Skip to content

Commit 461e87e

Browse files
committed
Added tests for contains function
1 parent e5a0167 commit 461e87e

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

Sprint-2/implement/contains.test.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,40 @@ as the object doesn't contains a key of 'c'
1616
// Given a contains function
1717
// When passed an object and a property name
1818
// Then it should return true if the object contains the property, false otherwise
19+
test("returns true when the property exists in the object", () => {
20+
expect(contains({ a: 1, b: 2 }, "a")).toBe(true);
21+
expect(contains({ a: 1, b: 2 }, "b")).toBe(true);
22+
});
1923

2024
// Given an empty object
2125
// When passed to contains
2226
// Then it should return false
23-
test.todo("contains on empty object returns false");
27+
test("contains on empty object returns false", () => {
28+
expect(contains({}, "a")).toBe(false);
29+
expect(contains({}, "toString")).toBe(false);
30+
});
2431

2532
// Given an object with properties
2633
// When passed to contains with an existing property name
2734
// Then it should return true
35+
test("returns true for existing property name", () => {
36+
expect(contains({ name: "Alex" }, "name")).toBe(true);
37+
expect(contains({ id: 42 }, "id")).toBe(true);
38+
});
2839

2940
// Given an object with properties
3041
// When passed to contains with a non-existent property name
3142
// Then it should return false
43+
test("returns false for non-existent property name", () => {
44+
expect(contains({ name: "Alex", age: 42 }, "email")).toBe(false);
45+
expect(contains({ age: 54 }, "name")).toBe(false);
46+
});
3247

3348
// Given invalid parameters like an array
3449
// When passed to contains
3550
// Then it should return false or throw an error
51+
test("handles invalid parameters like an array", () => {
52+
expect(contains([], "length")).toBe(false);
53+
expect(contains(123, "length")).toBe(false);
54+
expect(contains("string", "length")).toBe(false);
55+
});

0 commit comments

Comments
 (0)