Skip to content

Commit 95f9e07

Browse files
committed
Contains/ test / Excercise
1 parent 8ad77a6 commit 95f9e07

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

Sprint-2/implement/contains.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1-
function contains() {}
1+
function contains(someObject, propertyName) {
2+
let whatTheRobotFound = someObject[propertyName];
3+
if (someObject[propertyName] === undefined) {
4+
return false;
5+
} else {
6+
return true;
7+
};
8+
};
29

310
module.exports = contains;
11+
12+
// Implement a function called contains that checks an object contains a
13+
// particular property

Sprint-2/implement/contains.test.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,39 @@ 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+
test("contains on empty object returns false",() =>{
24+
const inputEmpty = [];
25+
const result = contains(inputEmpty);
26+
expect(result).toEqual(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
32+
test("Given an object with properties when pass to contains it returns true", () => {
33+
const myObject = {
34+
name: "Alice",
35+
age: 30,
36+
city: "London",
37+
};
38+
const result = contains(myObject, "name");
39+
expect(result).toEqual(true);
40+
});
2841

2942
// Given an object with properties
3043
// When passed to contains with a non-existent property name
3144
// Then it should return false
45+
test("give a object with proprieties when pass contains with non-exist proprity name it should return false", () => {
46+
const inputProprieties2 = ["f", "g", "h"];
47+
const result = contains(inputProprieties2);
48+
expect (result).toEqual(false);
49+
});
3250

3351
// Given invalid parameters like an array
3452
// When passed to contains
3553
// Then it should return false or throw an error
54+
test("invalid parameters should return false or throw an error", () => {
55+
const invalidParameters = ("f", "g", "h");
56+
const result = contains(invalidParameters);
57+
expect(result).toEqual(false);
58+
});

0 commit comments

Comments
 (0)