doocs/leetcode · error · Error

Equal

Error message

Equal

What it means

Thrown by the notToBe method of the LeetCode 2704 expect helper when val and expected turn out to be strictly equal (===). notToBe is the inverted assertion: it succeeds only when the two values differ. Receiving 'Equal' means the values you asserted were different are actually the same strict value.

Source

Thrown at solution/2700-2799/2704.To Be Or Not To Be/Solution.js:15

/**
 * @param {string} val
 * @return {Object}
 */
var expect = function (val) {
    return {
        toBe: function (expected) {
            if (val !== expected) {
                throw new Error('Not Equal');
            }
            return true;
        },
        notToBe: function (expected) {
            if (val === expected) {
                throw new Error('Equal');
            }
            return true;
        },
    };
};

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

View on GitHub (pinned to f84f361dc4)

Solutions

  1. Re-check the pair: notToBe throws exactly when val === expected
  2. If the values really are equal, use toBe instead
  3. Remember 0 === false is false, so expect(0).notToBe(false) correctly returns true
  4. When testing the function, assert the throw with toThrow('Equal')

Example fix

// before
expect(1).notToBe(1); // throws 'Equal'

// after
expect(1).notToBe(2); // true
expect(1).toBe(1);     // true
Defensive patterns

Strategy: validation

Validate before calling

if (val !== expected) { expect(val).notToBe(expected); } // else it would throw 'Equal'

Type guard

const isStrictlyUnequal = (a: unknown, b: unknown): boolean => a !== b;

Try / catch

try { expect(1).notToBe(x); } catch (e) { if ((e as Error).message !== 'Equal') throw e; }

Prevention

When it happens

Trigger: Calling expect(1).notToBe(1), expect(null).notToBe(null), or any notToBe comparison where both sides are the same primitive value or the same object reference.

Common situations: Mixing up toBe/notToBe semantics; testing the utility with pairs you believed were unequal (e.g. 0 vs false is actually unequal and passes, but 1 vs 1 fails); expecting notToBe to do deep comparison of objects (two references to the same object are 'Equal').

Related errors


AI-assisted analysis of doocs/leetcode@f84f361dc4 (2026-08-27). Data as JSON: /api/errors/8aab32059a88bebc. Report an issue: GitHub.