{"record":{"id":"8aab32059a88bebc","repo":"doocs/leetcode","slug":"equal","errorCode":null,"errorMessage":"Equal","messagePattern":"Equal","errorType":"error_code","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"solution/2700-2799/2704.To Be Or Not To Be/Solution.js","lineNumber":15,"sourceCode":"/**\n * @param {string} val\n * @return {Object}\n */\nvar expect = function (val) {\n    return {\n        toBe: function (expected) {\n            if (val !== expected) {\n                throw new Error('Not Equal');\n            }\n            return true;\n        },\n        notToBe: function (expected) {\n            if (val === expected) {\n                throw new Error('Equal');\n            }\n            return true;\n        },\n    };\n};\n\n/**\n * expect(5).toBe(5); // true\n * expect(5).notToBe(5); // throws \"Equal\"\n */\n","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/doocs/leetcode/blob/f84f361dc403a65c4c031f6e0774297cc377f00a/solution/2700-2799/2704.To Be Or Not To Be/Solution.js#L1-L26","documentation":"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.","triggerScenarios":"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.","commonSituations":"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').","solutions":["Re-check the pair: notToBe throws exactly when val === expected","If the values really are equal, use toBe instead","Remember 0 === false is false, so expect(0).notToBe(false) correctly returns true","When testing the function, assert the throw with toThrow('Equal')"],"exampleFix":"// before\nexpect(1).notToBe(1); // throws 'Equal'\n\n// after\nexpect(1).notToBe(2); // true\nexpect(1).toBe(1);     // true","handlingStrategy":"validation","validationCode":"if (val !== expected) { expect(val).notToBe(expected); } // else it would throw 'Equal'","typeGuard":"const isStrictlyUnequal = (a: unknown, b: unknown): boolean => a !== b;","tryCatchPattern":"try { expect(1).notToBe(x); } catch (e) { if ((e as Error).message !== 'Equal') throw e; }","preventionTips":["Verify values actually differ before notToBe","Keep toBe/notToBe message mapping straight"],"tags":["javascript","assertion","equality","leetcode"],"backgroundTag":"assertion-equality-failure","analyzedSha":"f84f361dc403a65c4c031f6e0774297cc377f00a","analyzedAt":"2026-08-27T04:29:31.522Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}