Revisions
-
wzr1337 revised this gist
Dec 28, 2015 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,6 +8,7 @@ describe('feat(localStorage Mock): ', function() { angular.module('mock-module',[]) }); // --- snip --- // Mock localStorage beforeEach(() => { var store = {}; @@ -25,6 +26,8 @@ describe('feat(localStorage Mock): ', function() { store = {}; }); }); // --- snap --- beforeEach(()=> { angular.mock.module('mock-module'); -
wzr1337 revised this gist
Dec 28, 2015 . 1 changed file with 17 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,7 @@ describe('feat(localStorage Mock): ', function() { // Mock localStorage beforeEach(() => { var store = {}; spyOn(localStorage, 'getItem').and.callFake( (key:string):String => { return store[key] || null; }); @@ -30,13 +30,26 @@ describe('feat(localStorage Mock): ', function() { angular.mock.module('mock-module'); }); it('should set an Item', () => { expect(localStorage.setItem('foo', 'bar')).toBe('bar'); // bar expect(localStorage.getItem('foo')).toBe('bar'); // bar }); it('should return null for non existing items', () => { expect(localStorage.getItem('foo')).toBeNull(); // null }); it('should set and remove Item', () => { expect(localStorage.setItem('foo', 'bar')).toBe('bar'); // bar expect(localStorage.removeItem('foo')).toBeUndefined(); // undefined expect(localStorage.getItem('foo')).toBeNull(); // null }); it('should clear the storage', () => { expect(localStorage.setItem('foo', 'bar')).toBe('bar'); // bar expect(localStorage.setItem('bar', 'foo')).toBe('foo'); // foo expect(localStorage.clear()).toBeUndefined(); // undefined expect(localStorage.getItem('foo')).toBeNull(); // null expect(localStorage.getItem('bar')).toBeNull(); // null }); }); -
wzr1337 created this gist
Dec 28, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ /// <reference path="../../library.test.d.ts"/> import * as angular from "angular"; angular; import * as mocks from "angular-mocks/ngMock"; mocks; describe('feat(localStorage Mock): ', function() { beforeAll(() => { angular.module('mock-module',[]) }); // Mock localStorage beforeEach(() => { var store = {}; spyOn(localStorage, 'getItem').and.callFake( (key:string):String => { return store[key] || null; }); spyOn(localStorage, 'removeItem').and.callFake((key:string):void => { delete store[key]; }); spyOn(localStorage, 'setItem').and.callFake((key:string, value:string):string => { return store[key] = <string>value; }); spyOn(localStorage, 'clear').and.callFake(() => { store = {}; }); }); beforeEach(()=> { angular.mock.module('mock-module'); }); it('should work with localStorage Mock', () => { expect(localStorage.setItem('foo', 'bar')).toBe('bar'); // bar expect(localStorage.getItem('foo')).toBe('bar'); // bar expect(localStorage.clear()).toBeUndefined(); // undefined expect(localStorage.getItem('foo')).toBeNull(); // null expect(localStorage.setItem('foo', 'bar')).toBe('bar');; // bar expect(localStorage.removeItem('foo')).toBeUndefined(); // undefined expect(localStorage.getItem('foo')).toBeNull(); // null }); });