Skip to content

Commit 03b31d9

Browse files
Support await plan (#8)
* Support `await plan` * be a thenable Signed-off-by: Matteo Collina <[email protected]> --------- Signed-off-by: Matteo Collina <[email protected]> Co-authored-by: Matteo Collina <[email protected]>
1 parent e8e854d commit 03b31d9

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,13 @@ test('wait', async (t) => {
8383

8484
await completed
8585
})
86+
87+
test('await plan', async (t) => {
88+
const plan = tspl(t, { plan: 1 })
89+
90+
setImmediate(() => {
91+
plan.strictEqual(1, 1)
92+
})
93+
94+
await plan
95+
})

tspl.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ function tspl (t, opts = {}) {
4545
end
4646
}
4747

48+
Object.defineProperty(res, 'then', {
49+
get () {
50+
return completed.then.bind(completed)
51+
}
52+
})
53+
4854
for (const method of Object.keys(assert)) {
4955
if (method.match(/^[a-z]/)) {
5056
res[method] = (...args) => {

0 commit comments

Comments
 (0)