fix(node/assert): deepStrictEqual now correctly handles Number objects#31233
Conversation
Fixes denoland#31172 The deepStrictEqual function was using asserts.equal() which doesn't properly handle boxed primitives like Number objects. Changed it to use isDeepStrictEqual() from comparisons.ts which correctly handles Number, String, Boolean, BigInt, and Symbol objects. Added test cases to verify: - deepStrictEqual throws AssertionError for different Number objects - deepStrictEqual passes for equal Number objects
|
@Tango992 The failures likely indicate a pre-existing issue with how parseArgs creates objects or how the tests compare them. Can you please review it and merge if possible? |
…totypes Fix hasOwnProperty and propertyIsEnumerable calls to use Object.prototype methods with .call() to work correctly with objects that have __proto__: null. This fixes the parse-args test failures that occurred after switching deepStrictEqual to use isDeepStrictEqual.
|
@Tango992 This is fixed now can you review it? |
Tango992
left a comment
There was a problem hiding this comment.
Thanks! Though I have a minor review:
Thanks @Tango992 |
#31233) Fixes #31172 ## Description The `deepStrictEqual` function was using `asserts.equal()` which doesn't properly handle boxed primitives like Number objects. Changed it to use `isDeepStrictEqual()` from `comparisons.ts` which correctly handles Number, String, Boolean, BigInt, and Symbol objects. ## Changes - Modified `ext/node/polyfills/assert.ts`: - Added import for `isDeepStrictEqual` from `ext:deno_node/internal/util/comparisons.ts` - Updated `deepStrictEqual` function to use `isDeepStrictEqual()` instead of `asserts.equal()` - Added test cases in `tests/unit_node/assert_test.ts`: - Test that `deepStrictEqual` throws `AssertionError` for different Number objects - Test that `deepStrictEqual` passes for equal Number objects ## Testing Added unit tests to verify: - `deepStrictEqual` throws `AssertionError` for different Number objects (e.g., `new Number(1)` vs `new Number(2)`) - `deepStrictEqual` passes for equal Number objects (e.g., `new Number(1)` vs `new Number(1)`) ## Related Issue #31172 - `assert.deepStrictEqual` does not throw exception for Number objects --------- Co-authored-by: Daniel Rahmanto <daniel.rahmanto@gmail.com>
Fixes #31172
Description
The
deepStrictEqualfunction was usingasserts.equal()which doesn't properly handle boxed primitives like Number objects. Changed it to useisDeepStrictEqual()fromcomparisons.tswhich correctly handles Number, String, Boolean, BigInt, and Symbol objects.Changes
Modified
ext/node/polyfills/assert.ts:isDeepStrictEqualfromext:deno_node/internal/util/comparisons.tsdeepStrictEqualfunction to useisDeepStrictEqual()instead ofasserts.equal()Added test cases in
tests/unit_node/assert_test.ts:deepStrictEqualthrowsAssertionErrorfor different Number objectsdeepStrictEqualpasses for equal Number objectsTesting
Added unit tests to verify:
deepStrictEqualthrowsAssertionErrorfor different Number objects (e.g.,new Number(1)vsnew Number(2))deepStrictEqualpasses for equal Number objects (e.g.,new Number(1)vsnew Number(1))Related Issue
#31172 -
assert.deepStrictEqualdoes not throw exception for Number objects