|
|
@ -673,6 +673,62 @@ describe("caching", function() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
describe("using native promises", function() { |
|
|
|
beforeEach(function() { |
|
|
|
cache = caching({ |
|
|
|
store: 'memory', |
|
|
|
max: 50, |
|
|
|
ttl: 5 * 60 |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should be able to chain with simple promise", function(done) { |
|
|
|
cache.wrap('key', function() { |
|
|
|
return 'OK'; |
|
|
|
}) |
|
|
|
.then(function(res) { |
|
|
|
assert.equal(res, 'OK'); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should be able to chain with cache function as a promise", function(done) { |
|
|
|
cache.wrap('key', function() { |
|
|
|
return new Promise(function(resolve) { |
|
|
|
resolve('OK'); |
|
|
|
}); |
|
|
|
}) |
|
|
|
.then(function(res) { |
|
|
|
assert.equal(res, 'OK'); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should be able to catch errors in cache function as a promise", function(done) { |
|
|
|
cache.wrap('key', function() { |
|
|
|
return new Promise(function(resolve, reject) { |
|
|
|
reject('NOK'); |
|
|
|
}); |
|
|
|
}) |
|
|
|
.then(function() { |
|
|
|
done(new Error('It should not call then since there is an error in the cache function!')); |
|
|
|
}) |
|
|
|
.catch(function() { |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should be able to chain with non-cacheable value", function(done) { |
|
|
|
cache.wrap('key', function() { |
|
|
|
return; |
|
|
|
}) |
|
|
|
.then(function(res) { |
|
|
|
assert.equal(res, undefined); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
describe("instantiating with no store passed in", function() { |
|
|
|