Skip to content

Instantly share code, notes, and snippets.

@AutoSponge
Created June 29, 2014 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AutoSponge/711ababad268abb954a3 to your computer and use it in GitHub Desktop.
Save AutoSponge/711ababad268abb954a3 to your computer and use it in GitHub Desktop.
using promises with Tape
var Promise = require( 'es6-promise' ).Promise;
function fn() {
return 1337;
}
function promise() {
return new Promise( function ( resolve, reject ) {
setTimeout( function () {
resolve( fn() );
}, 1000 );
} )
}
module.exports = {
fn: fn,
promise: promise
};
{
"name": "",
"version": "0.0.0",
"main": "index.js",
"scripts": {
"test": "tape tests/*.js"
},
"dependencies": {
"es6-promise": "^1.0.0",
"tape": "^2.13.3"
}
}
var test = require( 'tape' );
var testFn = require( '../' ).fn;
var testPromise = require( '../' ).promise;
var Promise = require('es6-promise').Promise;
test( 'promise test', function ( t ) {
t.plan( 2 );
t.ok( testFn() === 1337 );
testPromise()
.then( function ( answer ) {
t.ok( answer === 1337 );
} )
.catch( t.fail );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment