-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoBeOrNotToBe.js
More file actions
46 lines (39 loc) · 1.25 KB
/
toBeOrNotToBe.js
File metadata and controls
46 lines (39 loc) · 1.25 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
/**
* @param {string} val
* @return {Object}
*/
var expect = function (val) {
return {
toBe: function (newVal) {
if (val === newVal) {
return true
} else {
throw new Error("Not Equal")
}
},
notToBe: function (newVal) {
if (val !== newVal) {
return true
} else {
throw new Error("Equal")
}
}
}
};
/**
* expect(5).toBe(5); // true
* expect(5).notToBe(5); // throws "Equal"
*/
/*
Write a function expect that helps developers test their code. It should take in any value val and return an object with the following two functions.
toBe(val) accepts another value and returns true if the two values === each other. If they are not equal, it should throw an error "Not Equal".
notToBe(val) accepts another value and returns true if the two values !== each other. If they are equal, it should throw an error "Equal".
Example 1:
Input: func = () => expect(5).toBe(5)
Output: {"value": true}
Explanation: 5 === 5 so this expression returns true.
Example 2:
Input: func = () => expect(5).toBe(null)
Output: {"error": "Not Equal"}
Explanation: 5 !== null so this expression throw the error "Not Equal".
*/