Junior — Senior
Creating a function to check the expected result
livecode
Task condition
It is necessary to implement a function expect that returns an object with two checking methods toBe() and notToBe(). Each method compares the passed value with the expected one and either returns true or throws an error with the corresponding message.
const expect = (val) => {
};
/**
* expect(5).toBe(5); // true
* expect(5).notToBe(5); // throws "Equal"
*/
%
// Input: func = () => expect(5).toBe(5)
// Output: {"value": true}
// Explanation: 5 === 5 so this expression returns true.
// Input: func = () => expect(5).toBe(null)
// Output: {"error": "Not Equal"}
// Explanation: 5 !== null so this expression throw the error "Not Equal".
// Input: func = () => expect(5).notToBe(null)
// Output: {"value": true}
// Explanation: 5 !== null so this expression returns true.