diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-02-24 20:54:35 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-02-24 21:58:12 +0900 |
commit | a26d8a8a1bed48a77e062914c120a23ace7bb8cf (patch) | |
tree | 29ce84b9b03e87e818197b63d77e20e5a897cf0b /test/background/infrastructures/MemoryStorage.test.js | |
parent | 21788740c1d4ee28ce05d6bd09d37901d1d88b68 (diff) |
Capitalize background scripts
Diffstat (limited to 'test/background/infrastructures/MemoryStorage.test.js')
-rw-r--r-- | test/background/infrastructures/MemoryStorage.test.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/test/background/infrastructures/MemoryStorage.test.js b/test/background/infrastructures/MemoryStorage.test.js new file mode 100644 index 0000000..95d3780 --- /dev/null +++ b/test/background/infrastructures/MemoryStorage.test.js @@ -0,0 +1,44 @@ +import MemoryStorage from 'background/infrastructures/MemoryStorage'; + +describe("background/infrastructures/memory-storage", () => { + it('stores values', () => { + let cache = new MemoryStorage(); + cache.set('number', 123); + expect(cache.get('number')).to.equal(123); + + cache.set('string', '123'); + expect(cache.get('string')).to.equal('123'); + + cache.set('object', { hello: '123' }); + expect(cache.get('object')).to.deep.equal({ hello: '123' }); + }); + + it('returns undefined if no keys', () => { + let cache = new MemoryStorage(); + expect(cache.get('no-keys')).to.be.undefined; + }) + + it('stored on shared memory', () => { + let cache = new MemoryStorage(); + cache.set('red', 'apple'); + + cache = new MemoryStorage(); + let got = cache.get('red'); + expect(got).to.equal('apple'); + }); + + it('stored cloned objects', () => { + let cache = new MemoryStorage(); + let recipe = { sugar: '300g' }; + cache.set('recipe', recipe); + + recipe.salt = '20g' + let got = cache.get('recipe', recipe); + expect(got).to.deep.equal({ sugar: '300g' }); + }); + + it('throws an error with unserializable objects', () => { + let cache = new MemoryStorage(); + expect(() => cache.set('fn', setTimeout)).to.throw(); + }) +}); |