Skip to content

Commit 88edc83

Browse files
committed
Merge pull request #24 from eschwartz/fix-wrap-missing-callback
Fix wrap missing callback
2 parents 7e2477b + 0ee4730 commit 88edc83

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ CrispCache.prototype.get = function (key, options, callback) {
7979
callback = options;
8080
options = {};
8181
}
82+
if (!callback) {
83+
throw new Error('Unable to retrieve "' + key + '" from cache: no callback provided');
84+
}
8285

8386
if (this.cache[key] === undefined || options.forceFetch) {
8487
//Cache miss.

test/crisp-cache-test.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ describe("CrispCache", function () {
973973
cb(null, 'RETURN VAL');
974974
};
975975
var fetchCb = sinon.spy(function(fetchInfo) {
976-
return "Fetching key: " + fetchInfo.key;
976+
return "Fetching key: " + fetchInfo.key;
977977
});
978978
var hitCb = sinon.spy(function(fetchInfo) {
979979
return "Hit key: " + fetchInfo.key;
@@ -1131,7 +1131,7 @@ describe("CrispCache", function () {
11311131
assert.deepEqual(getOptions.callCount, 2, 'getOptions should be called once for every result');
11321132
});
11331133

1134-
it(' should complain if `getOptions` throws an error', function(done) {
1134+
it('should complain if `getOptions` throws an error', function(done) {
11351135
var cached = CrispCache.wrap(function(x, cb) { cb(null, 'foo') }, {
11361136
createKey: function(x) { return x; },
11371137
parseKey: function(x) { return [x]; },
@@ -1146,5 +1146,13 @@ describe("CrispCache", function () {
11461146
});
11471147
});
11481148

1149+
it('should complain if a wrapped function is called without a callback', function(done) {
1150+
const cached = CrispCache.wrap(function() {});
1151+
1152+
assert.throws(function() { cached() }, /callback/);
1153+
1154+
done();
1155+
});
1156+
11491157
});
11501158
});

0 commit comments

Comments
 (0)