From 67b4c8c99812246c0f50df3b4cc76c9dce1d7f60 Mon Sep 17 00:00:00 2001 From: Dave Date: Wed, 11 Nov 2020 19:24:36 +1100 Subject: [PATCH] #23 Added test for the reclaim Engine and fixed store reclaim engine test --- test/engine.test.js | 23 +++++++++++++++++++++++ test/store.test.js | 6 +++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/test/engine.test.js b/test/engine.test.js index b468780..3d5222a 100644 --- a/test/engine.test.js +++ b/test/engine.test.js @@ -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'); @@ -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); + }); + }); }); diff --git a/test/store.test.js b/test/store.test.js index c11104c..f91a5d4 100644 --- a/test/store.test.js +++ b/test/store.test.js @@ -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() {