Skip to content

Commit

Permalink
Add a test that done errors make it into domains. See kriskowal#120.
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed Nov 25, 2012
1 parent ab5961c commit 8baaa5d
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions spec/q-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1702,9 +1702,10 @@ if (typeof require === "function") {

if (domain) {
describe("node domain support", function () {
it("should work", function (done) {
it("should work for non-promise async inside a promise handler",
function (done) {
var error = new Error("should be caught by the domain");
var d = require("domain").create();
var d = domain.create();

d.run(function () {
Q.resolve().then(function () {
Expand All @@ -1724,6 +1725,26 @@ if (typeof require === "function") {
done();
});
});

it("should transfer errors from `done` into the domain",
function (done) {
var error = new Error("should be caught by the domain");
var d = domain.create();

d.run(function () {
Q.reject(error).done();
});

var errorTimeout = setTimeout(function () {
done(new Error("Wasn't caught"));
}, 100);

d.on("error", function (theError) {
expect(theError).toBe(error);
clearTimeout(errorTimeout);
done();
});
});
});
}
}
Expand Down

0 comments on commit 8baaa5d

Please sign in to comment.