To help developers test their code, you need to write a function named expect. This function can accept any value val and returns an object with the following two functionalities:
toBe(val): Accepts another value and returns true if the two values are equal (i.e., ===). If they are not equal, it throws an error with the message "Not Equal".notToBe(val): Accepts another value and returns true if the two values are not equal (i.e., !==). If they are equal, it throws an error with the message "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 throws the error "Not Equal".
function expect(value) {
function toBe(val){
if(value !== val){
throw new Error("Not Equal")
}
return true
}
function notToBe(val){
if(value == val){
throw new Error("Equal")
}
return true
}
return {
toBe,
notToBe
}
}