Skip to content

Commit

Permalink
test: Add testAsync() helper to Suite
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sehrope committed Jul 18, 2019
1 parent 83e8fa5 commit 1d331b4
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/suite.js
Expand Up @@ -72,6 +72,19 @@ class Suite {
const test = new Test(name, cb)
this._queue.push(test)
}

testAsync (name, action) {
const test = new Test(name, cb => {
try {
Promise.resolve(action())
.then(() => cb(null))
.catch((err) => cb(err))
} catch (err) {
cb(err)
}
})
this._queue.push(test)
}
}

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

0 comments on commit 1d331b4

Please sign in to comment.