Skip to content

Commit 573ace7

Browse files
authored
Add tests for 'contains' function
Added tests for the 'contains' function to validate behavior with various inputs, including empty objects, existing properties, non-existent properties, and invalid inputs.
1 parent 30e690a commit 573ace7

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
const contains = require("./contains.js");
2+
test("contains on empty object returns false", () => {
3+
expect(contains({}, "a")).toBe(false);
4+
});
5+
6+
test("returns true for existing property", () => {
7+
const obj = { a: 1, b: 2 };
8+
expect(contains(obj, "a")).toBe(true);
9+
});
10+
11+
test("returns false for non-existent property", () => {
12+
const obj = { a: 1, b: 2 };
13+
expect(contains(obj, "c")).toBe(false);
14+
});
15+
16+
test("invalid inputs (arrays, null, non-objects) return false", () => {
17+
expect(contains([], "0")).toBe(false);
18+
expect(contains(null, "a")).toBe(false);
19+
expect(contains(42, "a")).toBe(false);
20+
});
221

322
/*
423
Implement a function called contains that checks an object contains a

0 commit comments

Comments
 (0)