summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Promise/prototype/then/S25.4.4_A1.1_T1.js
blob: 30133bb8963975d17e21a8467c286a087fa4b8fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// |reftest| async
// Copyright 2014 Cubane Canada, Inc.  All rights reserved.
// See LICENSE for details.

/*---
info: |
   Misc sequencing tests
   inspired by https://github.com/getify/native-promise-only/issues/34#issuecomment-54282002
es6id: S25.4.2.1_A3.2_T2
author: Sam Mikes
description: Promise onResolved functions are called in predictable sequence
includes: [promiseHelper.js]
flags: [async]
---*/

var sequence = [];

var p = new Promise(function(resolve, reject) {
  sequence.push(1);
  resolve("");
});

p.then(function() {
  sequence.push(3);
}).then(function() {
  sequence.push(5);
}).then(function() {
  sequence.push(7);
});

p.then(function() {
  sequence.push(4);
}).then(function() {
  sequence.push(6);
}).then(function() {
  sequence.push(8);
}).then(function() {
  assert.sameValue(sequence.length, 8);
  checkSequence(sequence, "Sequence should be as expected");
}).then($DONE, $DONE);

sequence.push(2);