Skip to content

Commit 1d331b4

Browse files
committed
test: Add testAsync() helper to Suite
Add testAsync() helper function to Suite to simplify running tests that return a Promise. The test action is executed and if a syncronous error is thrown then it is immediately considered failed. If the Promise resolves successfully then the test is considered successful. If the Promise rejects with an Error then the test is considered failed.
1 parent 83e8fa5 commit 1d331b4

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Diff for: test/suite.js

+13
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ class Suite {
7272
const test = new Test(name, cb)
7373
this._queue.push(test)
7474
}
75+
76+
testAsync (name, action) {
77+
const test = new Test(name, cb => {
78+
try {
79+
Promise.resolve(action())
80+
.then(() => cb(null))
81+
.catch((err) => cb(err))
82+
} catch (err) {
83+
cb(err)
84+
}
85+
})
86+
this._queue.push(test)
87+
}
7588
}
7689

7790
process.on('unhandledRejection', (e) => {

0 commit comments

Comments
 (0)