mirror of
https://github.com/denoland/deno.git
synced 2025-12-23 08:48:24 +00:00
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>
64 lines
1.5 KiB
TypeScript
64 lines
1.5 KiB
TypeScript
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
import * as assert from "node:assert";
|
|
|
|
Deno.test("[node/assert] .throws() compares Error instance", () => {
|
|
assert.throws(
|
|
() => {
|
|
throw new Error("FAIL");
|
|
},
|
|
Error,
|
|
);
|
|
|
|
assert.throws(
|
|
() => {
|
|
throw new TypeError("FAIL");
|
|
},
|
|
TypeError,
|
|
);
|
|
});
|
|
|
|
Deno.test("[node/assert] deepStrictEqual(0, -0)", () => {
|
|
assert.throws(
|
|
() => {
|
|
assert.deepStrictEqual(0, -0);
|
|
},
|
|
);
|
|
});
|
|
|
|
Deno.test("[node/assert] CallTracker correctly exported", () => {
|
|
assert.strictEqual(typeof assert.CallTracker, "function");
|
|
assert.strictEqual(typeof assert.default.CallTracker, "function");
|
|
assert.strictEqual(assert.CallTracker, assert.default.CallTracker);
|
|
});
|
|
|
|
Deno.test("[node/assert] error message from strictEqual should be the same as AssertionError message", () => {
|
|
const { message } = new assert.AssertionError({
|
|
actual: 1,
|
|
expected: 2,
|
|
operator: "strictEqual",
|
|
});
|
|
|
|
assert.throws(
|
|
() => {
|
|
assert.strictEqual(1, 2);
|
|
},
|
|
{ message },
|
|
);
|
|
});
|
|
|
|
Deno.test("[node/assert] deepStrictEqual throws for different Number objects", () => {
|
|
// Test case from issue #31172
|
|
assert.throws(
|
|
() => {
|
|
assert.deepStrictEqual(new Number(1), new Number(2));
|
|
},
|
|
assert.AssertionError,
|
|
);
|
|
});
|
|
|
|
Deno.test("[node/assert] deepStrictEqual passes for equal Number objects", () => {
|
|
// Equal Number objects should pass
|
|
assert.doesNotThrow(() => {
|
|
assert.deepStrictEqual(new Number(1), new Number(1));
|
|
});
|
|
});
|