forked from CodeYourFuture/Module-Data-Groups
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontains.test.js
More file actions
44 lines (35 loc) · 1.57 KB
/
contains.test.js
File metadata and controls
44 lines (35 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const contains = require("./contains.js");
/*
Implement a function called contains that checks an object contains a
particular property
E.g. contains({a: 1, b: 2}, 'a') // returns true
as the object contains a key of 'a'
E.g. contains({a: 1, b: 2}, 'c') // returns false
as the object doesn't contains a key of 'c'
*/
// Acceptance criteria:
// Given a contains function
// When passed an object and a property name
// Then it should return true if the object contains the property, false otherwise
// Given an empty object
// When passed to contains
// Then it should return false
test("contains on empty object returns false", () =>
expect(contains({}, "a")).toBe(false));
// Given an object with properties
// When passed to contains with an existing property name
// Then it should return true
test("returns true when an object contains a property that matches the one passed to contains", () =>
expect(contains({ area: "Manchester" }, "area")).toBe(true));
// Given an object with properties
// When passed to contains with a non-existent property name
// Then it should return false
test("returns false when an object with properties is passed to contains with a non-existent property name", () =>
expect(contains({ area: "Manchester" }, "town")).toBe(false));
// Given invalid parameters like an array
// When passed to contains
// Then it should return false or throw an error
test("should throw an error when when an invalid parameter like an array is passed to contains", () =>
expect(() => contains([1, 4], 4)).toThrow(
"error invalid parameter please provide an object"
));