Debian Codegraph @

js/src/tests/test262/harness/asyncHelpers-throwsAsync-incorrect-ctor.js

raw
1 // |reftest| async
2 // Copyright (C) 2022 Igalia, S.L. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4 /*---
5 description: |
6 Thenables that reject with values whose constructor does not match the specified
7 constructor do not satisfy the assertion.
8 flags: [async]
9 includes: [asyncHelpers.js]
10 ---*/
11
12 asyncTest(async function () {
13 var caught = false;
14
15 const p = assert.throwsAsync(Error, function () {
16 return Promise.reject(new TypeError());
17 });
18 assert(p instanceof Promise);
19 try {
20 await p;
21 } catch (err) {
22 caught = true;
23 assert.sameValue(
24 err.constructor,
25 Test262Error,
26 "Expected a Test262Error, but a '" +
27 err.constructor.name +
28 "' was thrown."
29 );
30 } finally {
31 assert(
32 caught,
33 "assert.throwsAsync did not reject when a value with incorrect constructor was thrown"
34 );
35 }
36 });