Skip to content

Commit

Permalink
Unit tests for thrown errors in the work function.
Browse files Browse the repository at this point in the history
  • Loading branch information
aletorrado committed Dec 18, 2014
1 parent 7bd7e9e commit a6cb298
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/caching.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,23 @@ describe("caching", function () {
});
});

context("when an error is thrown in the work function", function () {
var fake_error;

beforeEach(function() {
fake_error = new Error(support.random.string());
});

it("bubbles up that error", function (done) {
cache.wrap(key, function () {
throw fake_error;
}, ttl, function (err) {
assert.equal(err, fake_error);
done();
});
});
});

context("when store.get() calls back with an error", function () {
context("and ignoreCacheErrors is not set (default is false)", function () {
it("bubbles up that error", function (done) {
Expand Down
17 changes: 17 additions & 0 deletions test/multi_caching.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,23 @@ describe("multi_caching", function () {
memory_store.create.restore();
});

context("when an error is thrown in the work function", function () {
var fake_error;

beforeEach(function() {
fake_error = new Error(support.random.string());
});

it("bubbles up that error", function (done) {
multi_cache.wrap(key, function () {
throw fake_error;
}, ttl, function (err) {
assert.equal(err, fake_error);
done();
});
});
});

context("when store.get() calls back with an error", function () {
it("bubbles up that error", function (done) {
var fake_error = new Error(support.random.string());
Expand Down

0 comments on commit a6cb298

Please sign in to comment.