1
1
'use strict' ;
2
2
3
3
const common = require ( '../../common' ) ;
4
- const test_promise = require ( `./build/${ common . buildType } /test_promise` ) ;
4
+
5
+ // This tests the promise-related n-api calls
6
+
5
7
const assert = require ( 'assert' ) ;
8
+ const test_promise = require ( `./build/${ common . buildType } /test_promise` ) ;
6
9
7
10
// A resolution
8
11
{
9
12
const expected_result = 42 ;
10
13
const promise = test_promise . createPromise ( ) ;
11
14
promise . then (
12
15
common . mustCall ( function ( result ) {
13
- assert . strictEqual ( result , expected_result ,
14
- `promise resolved as expected, received ${ result } ` ) ;
16
+ assert . strictEqual ( result , expected_result ) ;
15
17
} ) ,
16
18
common . mustNotCall ( ) ) ;
17
19
test_promise . concludeCurrentPromise ( expected_result , true ) ;
@@ -24,23 +26,24 @@ const assert = require('assert');
24
26
promise . then (
25
27
common . mustNotCall ( ) ,
26
28
common . mustCall ( function ( result ) {
27
- assert . strictEqual ( result , expected_result ,
28
- `promise rejected as expected, received ${ result } ` ) ;
29
+ assert . strictEqual ( result , expected_result ) ;
29
30
} ) ) ;
30
31
test_promise . concludeCurrentPromise ( expected_result , false ) ;
31
32
}
32
33
33
34
// 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 ) ;
35
+ {
36
+ const expected_result = 'chained answer' ;
37
+ const promise = test_promise . createPromise ( ) ;
38
+ promise . then (
39
+ common . mustCall ( function ( result ) {
40
+ assert . strictEqual ( result , expected_result ) ;
41
+ } ) ,
42
+ common . mustNotCall ( ) ) ;
43
+ test_promise . concludeCurrentPromise ( Promise . resolve ( 'chained answer' ) , true ) ;
44
+ }
42
45
43
- assert . strictEqual ( test_promise . isPromise ( promise ) , true ) ;
46
+ assert . strictEqual ( test_promise . isPromise ( test_promise . createPromise ( ) ) , 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