Skip to content

Commit

Permalink
chore(test): do better testing of promise getters
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Oct 23, 2019
1 parent fb3630a commit c077dbe
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion test/loopback.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { test } from 'tape-promise/tape';
import { E, harden, makeCapTP } from '../lib/captp';

// TODO: remove .only when you have this test working
test('try loopback captp', async t => {
try {
const debug = false;
Expand All @@ -15,6 +14,11 @@ test('try loopback captp', async t => {
rightDispatch(obj);
},
);
const pr = {};
pr.p = new Promise((resolve, reject) => {
pr.res = resolve;
pr.rej = reject;
});
({ dispatch: rightDispatch } = makeCapTP(
'right',
obj => {
Expand All @@ -24,6 +28,7 @@ test('try loopback captp', async t => {
leftDispatch(obj);
},
harden({
promise: pr.p,
encourager: {
encourage(name) {
const bang = new Promise(resolve => {
Expand All @@ -48,6 +53,9 @@ test('try loopback captp', async t => {
).P;
t.equal(comment, 'good work, buddy', 'got encouragement');
t.equal(await E(bang).trigger(), 'buddy BANG!', 'called on promise');
pr.res('resolution');
t.equal(await E.G(rightRef).promise, 'resolution', 'got resolution');
t.equal(await E.C(rightRef).G.promise.P, 'resolution', 'chained resolution');
} catch (e) {
t.isNot(e, e, 'unexpected exception');
} finally {
Expand Down

0 comments on commit c077dbe

Please sign in to comment.