diff --git a/lib/index.js b/lib/index.js index 6160b20..f1adffe 100644 --- a/lib/index.js +++ b/lib/index.js @@ -6,5 +6,6 @@ module.exports = { promisify: require("./promisify"), repeat: require("./repeat"), forEach: require("./forEach"), - queue: require("./queue") + queue: require("./queue"), + timeout: require("./timeout") }; diff --git a/test/test.js b/test/test.js index 001addb..f4c4992 100644 --- a/test/test.js +++ b/test/test.js @@ -274,3 +274,21 @@ test("promisify: error", function(t) { t.equal(err.message, "TEST"); }).then(t.end, t.end); }); + +test("timeout: basic", function(t) { + pbox.timeout(Promise.resolve(), 1000).then(function() { + t.pass("already resolved promise"); + }).catch(function() { + t.fail("should not get here"); + }).then(t.end, t.end); +}); + +test("timeout: error", function(t) { + pbox.timeout(new Promise(function(resolve) { + setTimeout(resolve, 500); + }), 1).then(function() { + t.fail("should not get here"); + }).catch(function(err) { + t.equal(err.code, "TIMEOUT_ERROR"); + }).then(t.end, t.end); +});