diff options
-rw-r--r-- | ext/node/polyfills/assert.ts | 7 | ||||
-rw-r--r-- | tests/integration/node_unit_tests.rs | 1 | ||||
-rw-r--r-- | tests/unit_node/assert_test.ts | 18 |
3 files changed, 24 insertions, 2 deletions
diff --git a/ext/node/polyfills/assert.ts b/ext/node/polyfills/assert.ts index 3d7660487..00677e3f7 100644 --- a/ext/node/polyfills/assert.ts +++ b/ext/node/polyfills/assert.ts @@ -17,6 +17,9 @@ import { ERR_MISSING_ARGS, } from "ext:deno_node/internal/errors.ts"; import { isDeepEqual } from "ext:deno_node/internal/util/comparisons.ts"; +import { primordials } from "ext:core/mod.js"; + +const { ObjectPrototypeIsPrototypeOf } = primordials; function innerFail(obj: { actual?: unknown; @@ -744,8 +747,8 @@ function validateThrownError( error = undefined; } if ( - error instanceof Function && error.prototype !== undefined && - error.prototype instanceof Error + typeof error === "function" && + (error === Error || ObjectPrototypeIsPrototypeOf(Error, error)) ) { // error is a constructor if (e instanceof error) { diff --git a/tests/integration/node_unit_tests.rs b/tests/integration/node_unit_tests.rs index 15d2021c1..4f0b61378 100644 --- a/tests/integration/node_unit_tests.rs +++ b/tests/integration/node_unit_tests.rs @@ -53,6 +53,7 @@ util::unit_test_factory!( _fs_writeFile_test = _fs / _fs_writeFile_test, _fs_write_test = _fs / _fs_write_test, async_hooks_test, + assert_test, assertion_error_test, buffer_test, child_process_test, diff --git a/tests/unit_node/assert_test.ts b/tests/unit_node/assert_test.ts new file mode 100644 index 000000000..dc565458f --- /dev/null +++ b/tests/unit_node/assert_test.ts @@ -0,0 +1,18 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. 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, + ); +}); |