diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-07-28 17:06:20 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-07-28 17:10:08 +0900 |
commit | 691e9ca8f28a8430e4765ab1a9ae13687289a53b (patch) | |
tree | e464cbed67281469841c04908196939cb449597f | |
parent | b3dafedf8819d79fbcdb19ea0a9de4ff102b7f55 (diff) |
Fix last tab is undefined
-rw-r--r-- | src/background/infrastructures/memory-storage.js | 6 | ||||
-rw-r--r-- | src/background/usecases/operation.js | 4 | ||||
-rw-r--r-- | test/background/infrastructures/memory-storage.test.js | 5 |
3 files changed, 13 insertions, 2 deletions
diff --git a/src/background/infrastructures/memory-storage.js b/src/background/infrastructures/memory-storage.js index 234a9b8..3a7e4f2 100644 --- a/src/background/infrastructures/memory-storage.js +++ b/src/background/infrastructures/memory-storage.js @@ -10,6 +10,10 @@ export default class MemoryStorage { } get(name) { - return JSON.parse(db[name]); + let data = db[name]; + if (!data) { + return undefined; + } + return JSON.parse(data); } } diff --git a/src/background/usecases/operation.js b/src/background/usecases/operation.js index f19c632..86f39ca 100644 --- a/src/background/usecases/operation.js +++ b/src/background/usecases/operation.js @@ -183,7 +183,9 @@ export default class OperationInteractor { onTabSelected(tabId) { let lastId = this.cache.get(CURRENT_SELECTED_KEY); - this.cache.set(LAST_SELECTED_KEY, lastId); + if (lastId) { + this.cache.set(LAST_SELECTED_KEY, lastId); + } this.cache.set(CURRENT_SELECTED_KEY, tabId); } } diff --git a/test/background/infrastructures/memory-storage.test.js b/test/background/infrastructures/memory-storage.test.js index 5d62880..0fea895 100644 --- a/test/background/infrastructures/memory-storage.test.js +++ b/test/background/infrastructures/memory-storage.test.js @@ -15,6 +15,11 @@ describe("background/infrastructures/memory-storage", () => { 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'); |