1
1
'use strict' ;
2
2
3
3
const common = require ( '../../common' ) ;
4
- const test_promise = require ( `./build/${ common . buildType } /test_promise` ) ;
5
4
const assert = require ( 'assert' ) ;
6
5
6
+ // Testing api calls for promises
7
+ const test_promise = require ( `./build/${ common . buildType } /test_promise` ) ;
8
+
7
9
// A resolution
8
10
{
9
11
const expected_result = 42 ;
10
12
const promise = test_promise . createPromise ( ) ;
11
13
promise . then (
12
14
common . mustCall ( function ( result ) {
13
- assert . strictEqual ( result , expected_result ,
14
- `promise resolved as expected, received ${ result } ` ) ;
15
+ assert . strictEqual ( result , expected_result ) ;
15
16
} ) ,
16
17
common . mustNotCall ( ) ) ;
17
18
test_promise . concludeCurrentPromise ( expected_result , true ) ;
@@ -24,23 +25,25 @@ const assert = require('assert');
24
25
promise . then (
25
26
common . mustNotCall ( ) ,
26
27
common . mustCall ( function ( result ) {
27
- assert . strictEqual ( result , expected_result ,
28
- `promise rejected as expected, received ${ result } ` ) ;
28
+ assert . strictEqual ( result , expected_result ) ;
29
29
} ) ) ;
30
30
test_promise . concludeCurrentPromise ( expected_result , false ) ;
31
31
}
32
32
33
33
// Chaining
34
- const promise = test_promise . createPromise ( ) ;
35
- promise . then (
36
- common . mustCall ( function ( result ) {
37
- assert . strictEqual ( result , 'chained answer' ,
38
- 'resolving with a promise chains properly' ) ;
39
- } ) ,
40
- common . mustNotCall ( ) ) ;
41
- test_promise . concludeCurrentPromise ( Promise . resolve ( 'chained answer' ) , true ) ;
34
+ {
35
+ const expected_result = 'chained answer' ;
36
+ const promise = test_promise . createPromise ( ) ;
37
+ promise . then (
38
+ common . mustCall ( function ( result ) {
39
+ assert . strictEqual ( result , expected_result ) ;
40
+ } ) ,
41
+ common . mustNotCall ( ) ) ;
42
+ test_promise . concludeCurrentPromise ( Promise . resolve ( 'chained answer' ) , true ) ;
43
+
44
+ assert . strictEqual ( test_promise . isPromise ( promise ) , true ) ;
45
+ }
42
46
43
- assert . strictEqual ( test_promise . isPromise ( promise ) , true ) ;
44
47
assert . strictEqual ( test_promise . isPromise ( Promise . reject ( - 1 ) ) , true ) ;
45
48
assert . strictEqual ( test_promise . isPromise ( 2.4 ) , false ) ;
46
49
assert . strictEqual ( test_promise . isPromise ( 'I promise!' ) , false ) ;
0 commit comments