tape-promise
Promise and ES2016 (ES7) async/await
support for Tape.
This module assumes that you're familiar with at least the concepts of Promises
and if you want to use async/await
, then you must be familiar with Babel.
Install
npm i --save-dev tape-promise
Usage
Make sure that you have tape
installed:
npm i --save-dev tape
Unlike blue-tape
, tape-promise
is
just a decorator (not an ES7 decorator). That is, it does NOT depend upon tape
and requires that you pass it in.
ES5
var tape = var _test = default // <---- notice 'default'var test = // decorate tape
ES6 (ES2015)
const test = // decorate tape
or, for convenience...
but you must explicitly have tape
as a dependency.
Example (promises)
Just return the promise.
// example function that returns a Promise { return { }}
Example (async/await)
Async/await functions just transform to Promises.
Don't forget to put the async
keyword on your function.
// example function that returns a Promise// it could also be an async function { return { }} // NOTICE 'async'?
Example (normal tape tests)
Of course you can write normal tape tests as you would.
New Assertions
t.rejects(promise, expected, msg)
Assert that the promise will reject.
If promise
is a function, then it is called, and the returned promise is used.
expected
is the error that should be rejected with, if present, must be a RegExp
or Function
. The RegExp
matches the string representation of the exception, as generated by err.toString()
. The Function
is the exception thrown (e.g. Error
). If the promise rejects, but its error doesn't match expected
, then the assertion fails.
msg
is an optional description of the assertion.
This function returns a promise that resolves when the assertion is complete (after the promise is settled). The test will not wait for the assertion automatically, so it needs to be await
ed.
t.doesNotReject(promise, expected, msg)
Assert that the promise will resolve.
If promise
is a function, then it is called, and the returned promise is used.
expected
is the error that the promise shouldn't reject with, if present, it must be a RegExp
or Function
. The RegExp
matches the string representation of the exception, as generated by err.toString()
. The Function
is the exception thrown (e.g. Error
). If the promise rejects, but its error doesn't match expected
, then the assertion passes.
msg
is an optional description of the assertion.
This function returns a promise that resolves when the assertion is complete (after the promise is settled). The test will not wait for the assertion automatically, so it needs to be await
ed.
example
License
Licensed under MIT
Copyright (c) JP Richardson