Debian Codegraph @

js/src/tests/test262/harness/asyncHelpers-asyncTest-then-resolves.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 The 'asyncTest' helper calls $DONE with undefined, regardless of what value the promise resolves with
7 flags: [async]
8 includes: [asyncHelpers.js]
9 ---*/
10 var doneCalls = 0;
11 var realDone = $DONE;
12 globalThis.$DONE = function (noError) {
13 doneCalls++;
14 assert.sameValue(
15 noError,
16 undefined,
17 "asyncTest should discard promise's resolved value"
18 );
19 };
20
21 (async function () {
22 asyncTest(function () {
23 return Promise.resolve(null);
24 });
25 })()
26 .then(() => {
27 assert.sameValue(doneCalls, 1, "asyncTest called $DONE with undefined");
28 asyncTest(function () {
29 return Promise.resolve({});
30 });
31 })
32 .then(() => {
33 assert.sameValue(doneCalls, 2, "asyncTest called $DONE with undefined");
34 asyncTest(function () {
35 return Promise.resolve("hi");
36 });
37 })
38 .then(() => {
39 assert.sameValue(doneCalls, 3, "asyncTest called $DONE with undefined");
40 asyncTest(function () {
41 return Promise.resolve(10);
42 });
43 })
44 .then(() => {
45 assert.sameValue(doneCalls, 4, "asyncTest called $DONE with undefined");
46 asyncTest(function () {
47 return {
48 then(res, rej) {
49 res(true);
50 },
51 };
52 });
53 })
54 .then(() => {
55 assert.sameValue(doneCalls, 5, "asyncTest called $DONE with undefined");
56 })
57 .then(realDone, realDone);