Created
June 29, 2014 19:49
-
-
Save AutoSponge/711ababad268abb954a3 to your computer and use it in GitHub Desktop.
using promises with Tape
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "", | |
"version": "0.0.0", | |
"main": "index.js", | |
"scripts": { | |
"test": "tape tests/*.js" | |
}, | |
"dependencies": { | |
"es6-promise": "^1.0.0", | |
"tape": "^2.13.3" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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