forked from TheOdinProject/javascript-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontains-solution.spec.js
More file actions
60 lines (50 loc) · 1.59 KB
/
contains-solution.spec.js
File metadata and controls
60 lines (50 loc) · 1.59 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const contains = require("./contains-solution");
describe("contains", () => {
const meaningOfLifeArray = [42];
const object = {
data: {
duplicate: "e",
stuff: {
thing: {
banana: NaN,
moreStuff: {
something: "foo",
answer: meaningOfLifeArray,
},
},
},
info: {
duplicate: "e",
magicNumber: 44,
empty: null,
},
},
};
test("true if the provided number is a value within the object", () => {
expect(contains(object, 44)).toBe(true);
});
test("true if the provided string is a value within the object", () => {
expect(contains(object, "foo")).toBe(true);
});
test("does not convert input string into a number when searching for a value within the object", () => {
expect(contains(object, "44")).toBe(false);
});
test("false if the provided string is not a value within the object", () => {
expect(contains(object, "bar")).toBe(false);
});
test("true if provided string is within the object, even if duplicated", () => {
expect(contains(object, "e")).toBe(true);
});
test("true if the object contains the same object by reference", () => {
expect(contains(object, meaningOfLifeArray)).toBe(true);
});
test("false if no matching object reference", () => {
expect(contains(object, [42])).toBe(false);
});
test("true if NaN is a value within the object", () => {
expect(contains(object, NaN)).toBe(true);
});
test("true if the provided value exists and is null", () => {
expect(contains(object, null)).toBe(true);
});
});