lru-memoizer.bypass.test.js 822 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. const memoizer = require('../lib/index.js');
  2. const assert = require('chai').assert;
  3. describe('lru-memoizer (bypass)', function () {
  4. var loadTimes = 0, memoized;
  5. beforeEach(function () {
  6. loadTimes = 0;
  7. memoized = memoizer({
  8. load: function (a, b, callback) {
  9. loadTimes++;
  10. callback(null, a + b);
  11. },
  12. hash: function (a, b) {
  13. return a + '-' + b;
  14. },
  15. bypass: function (a, b) {
  16. return a < b;
  17. },
  18. max: 10
  19. });
  20. });
  21. it('should call the load function every time', function (done) {
  22. memoized(1, 2, function (err) {
  23. assert.isNull(err);
  24. assert.strictEqual(loadTimes, 1);
  25. memoized(1, 2, function (err) {
  26. assert.isNull(err);
  27. assert.strictEqual(loadTimes, 2);
  28. done();
  29. });
  30. });
  31. });
  32. });