From 6e482dfbbd800c5d346524535744f2c9d23402c8 Mon Sep 17 00:00:00 2001 From: Max Jung Date: Tue, 11 Oct 2016 21:24:38 -0700 Subject: [PATCH] Add test cases for timeout --- lib/index.js | 3 ++- test/test.js | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) 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); +});