1
1
import { test } from 'tape-promise/tape' ;
2
2
import { E , harden , makeCapTP } from '../lib/captp' ;
3
3
4
- // TODO: remove .only when you have this test working
5
4
test ( 'try loopback captp' , async t => {
6
5
try {
7
6
const debug = false ;
@@ -15,6 +14,11 @@ test('try loopback captp', async t => {
15
14
rightDispatch ( obj ) ;
16
15
} ,
17
16
) ;
17
+ const pr = { } ;
18
+ pr . p = new Promise ( ( resolve , reject ) => {
19
+ pr . res = resolve ;
20
+ pr . rej = reject ;
21
+ } ) ;
18
22
( { dispatch : rightDispatch } = makeCapTP (
19
23
'right' ,
20
24
obj => {
@@ -24,6 +28,7 @@ test('try loopback captp', async t => {
24
28
leftDispatch ( obj ) ;
25
29
} ,
26
30
harden ( {
31
+ promise : pr . p ,
27
32
encourager : {
28
33
encourage ( name ) {
29
34
const bang = new Promise ( resolve => {
@@ -48,6 +53,9 @@ test('try loopback captp', async t => {
48
53
) . P ;
49
54
t . equal ( comment , 'good work, buddy' , 'got encouragement' ) ;
50
55
t . equal ( await E ( bang ) . trigger ( ) , 'buddy BANG!' , 'called on promise' ) ;
56
+ pr . res ( 'resolution' ) ;
57
+ t . equal ( await E . G ( rightRef ) . promise , 'resolution' , 'got resolution' ) ;
58
+ t . equal ( await E . C ( rightRef ) . G . promise . P , 'resolution' , 'chained resolution' ) ;
51
59
} catch ( e ) {
52
60
t . isNot ( e , e , 'unexpected exception' ) ;
53
61
} finally {
0 commit comments