Skip to content

Commit 5dcae6a

Browse files
committed
add two tests and implement function acordingly
1 parent 522cb56 commit 5dcae6a

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

‎Sprint-2/implement/contains.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
function contains() {}
1+
function contains(obj, prop) {
2+
return prop in obj; // checks if the property exists in the object and returns true or false
3+
}
24

35
module.exports = contains;

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@ 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("contains an object returns true, or false otherwise", () => {
20+
expect(contains({a: 1, b: 2, c: 3}, "a")).toBe(true);
21+
});
1922

2023
// Given an empty object
2124
// When passed to contains
2225
// Then it should return false
23-
test.todo("contains on empty object returns false");
26+
test("contains on empty object returns false", () => {
27+
expect(contains({}, "a")).toBe(false);
28+
});
2429

2530
// Given an object with properties
2631
// When passed to contains with an existing property name

0 commit comments

Comments
 (0)