Skip to content

Commit

Permalink
Add test cases for timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
asyncmax committed Oct 12, 2016
1 parent 8c5e103 commit 6e482df
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ module.exports = {
promisify: require("./promisify"),
repeat: require("./repeat"),
forEach: require("./forEach"),
queue: require("./queue")
queue: require("./queue"),
timeout: require("./timeout")
};
18 changes: 18 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit 6e482df

Please sign in to comment.