{"record":{"id":"7b7949e8603bf7b6","repo":"doocs/leetcode","slug":"not-equal","errorCode":null,"errorMessage":"Not Equal","messagePattern":"Not Equal","errorType":"error_code","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"solution/2700-2799/2704.To Be Or Not To Be/Solution.js","lineNumber":9,"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":"This error is thrown by a hand-rolled expect(val).toBe(expected) assertion helper for LeetCode problem 2704. It uses strict equality (!==), so toBe rejects any pair that is not strictly equal, including cases where == would pass such as 1 vs '1' or two objects with identical contents. The thrown Error('Not Equal') is the expected output the judge captures via expect(() => ...).toThrow().","triggerScenarios":"Calling expect(5).toBe('5') (type mismatch under ===), expect({}).toBe({}) (different object identities), or any value/expected pair that fails strict equality.","commonSituations":"Writing or testing the assertion utility itself; confusing === with ==; expecting toBe to behave like deep equality (e.g. comparing objects or arrays); accidentally comparing NaN (NaN !== NaN always throws here).","solutions":["Confirm the mismatch is intended: toBe is strict (===) equality, so '5' vs 5 or two separately-created objects are correctly 'Not Equal'","If you expected deep equality, compare JSON.stringify(val) === JSON.stringify(expected) or use a deep-equal helper instead","Use notToBe when you want the assertion to pass on unequal values","Wrap the call in expect(() => fn()).toThrow('Not Equal') when testing the thrower itself"],"exampleFix":"// before\nexpect('5').toBe(5); // throws 'Not Equal'\n\n// after\nexpect(Number('5')).toBe(5); // passes\n// or assert the throw:\njest.fn(() => expect('5').toBe(5)); // toThrow('Not Equal')","handlingStrategy":"validation","validationCode":"if (val === expected) { /* toBe will pass */ } else { /* toBe will throw 'Not Equal' */ }","typeGuard":"const isStrictlyEqual = (a: unknown, b: unknown): boolean => a === b;","tryCatchPattern":"try { expect(5).toBe(x); } catch (e) { if ((e as Error).message !== 'Not Equal') throw e; /* handle mismatch */ }","preventionTips":["Normalize types before asserting","Use deep comparison for objects/arrays","Remember NaN !== NaN"],"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"}