From 80fb0e986f84959826dd7df262084e416e65f205 Mon Sep 17 00:00:00 2001 From: Daniel Kucal Date: Wed, 17 Jan 2018 08:16:58 +0100 Subject: [PATCH] tests(WebStorageService): add test cases for WebStorageService.update() method --- tests/services/web-storage.service.spec.ts | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/services/web-storage.service.spec.ts b/tests/services/web-storage.service.spec.ts index e9f383a..586980e 100644 --- a/tests/services/web-storage.service.spec.ts +++ b/tests/services/web-storage.service.spec.ts @@ -39,6 +39,33 @@ function test(storageService: typeof WebStorageService) { }); }); + describe('#update() method', () => { + it('should merge changes with saved object', () => { + service.update('object', { property: 8 }); + expect(service.get('object')).toEqual({ + property: 8, + nested: { property: null }, + }, 'non-nested change'); + service.update('object', { nested: { property: true }}); + expect(service.get('object')).toEqual({ + property: 8, + nested: { property: true }, + }, 'nested change'); + }); + + it('should create new object if it does not exists', () => { + service.update('newObject', {a: 1}); + expect(service.get('newObject')).toEqual({a: 1}); + }); + + it('should throw an error when trying to update non-object', () => { + Object.entries(entries).forEach(([value, key]) => { + if (typeof value === 'object') return; + expect(service.update.bind(null, key.toString(), {b: 2})).toThrowError(); + }); + }); + }); + describe('should delete specified data', () => { const expectation = /null|undefined/; it('by key', () => {