2025-08-21 15:37:36 +0300 MSK

To Be Or Not To Be

Code

class Check {
    constructor(val) {
        this.val = val;
    }
    toBe(val) {
        if (val === this.val) {
            return true;
        }
        throw new Error("Not Equal");
    }
    notToBe(val) {
        if (val !== this.val) {
            return true;
        }
        throw new Error("Equal");
    }
}

/**
 * @param {string} val
 * @return {Object}
 */
var expect = function(val) {
    return new Check(val);  
};

/**
 * expect(5).toBe(5); // true
 * expect(5).notToBe(5); // throws "Equal"
 */