Skip to content

Commit

Permalink
segmentio#23 Added test for the reclaim Engine and fixed store reclai…
Browse files Browse the repository at this point in the history
…m engine test
  • Loading branch information
Dave committed Mar 11, 2021
1 parent e744bfa commit 67b4c8c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
23 changes: 23 additions & 0 deletions test/engine.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var defaultEngine = require('../lib/engine').defaultEngine;
var reclaimEngine = require('../lib/engine').reclaimEngine;
var inMemoryEngine = require('../lib/engine').inMemoryEngine;
var assert = require('proclaim');

Expand Down Expand Up @@ -53,4 +54,26 @@ describe('localStorage', function() {
assert.strictEqual(engine.length, 0);
});
});

describe('when using reclaimEngine', function() {
beforeEach(function() {
engine = reclaimEngine;
engine.clear();
});

it('should function', function() {
engine.setItem('test-key', 'abc');
assert.strictEqual(engine.getItem('test-key'), 'abc');
assert.strictEqual(engine.length, 1);
assert.strictEqual(engine.key(0), 'test-key');

engine.removeItem('test-key');
assert.strictEqual(engine.getItem('test-key'), null);
assert.strictEqual(engine.length, 0);

engine.setItem('test-key', 'abc');
engine.clear();
assert.strictEqual(engine.length, 0);
});
});
});
6 changes: 3 additions & 3 deletions test/store.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ describe('Store', function() {
assert.strictEqual(store.engine, inMemoryEngine);
});

it('should not switch the original storage mechanism', function() {
assert.strictEqual(store.getOriginalEngine(), engine);
it('should not switch the reclaim storage mechanism', function() {
assert.strictEqual(store.getReclaimEngine(), engine);
store._swapEngine();
assert.strictEqual(store.getOriginalEngine(), engine);
assert.strictEqual(store.getReclaimEngine(), engine);
});

it('should swap upon quotaExceeded on set', function() {
Expand Down

0 comments on commit 67b4c8c

Please sign in to comment.