Skip to content

Commit

Permalink
Brings coverage of unit tests up to 100 per cent
Browse files Browse the repository at this point in the history
  • Loading branch information
hfwittmann committed Apr 25, 2017
1 parent 7b400e7 commit 3e2551f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/pages/page2/page2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('Pages: Page2', () => {
fixture = TestBed.createComponent(Page2);
instance = fixture;
fixture.detectChanges();
fixture.componentInstance.onGainChange();
});
}));

Expand Down
8 changes: 8 additions & 0 deletions src/services/clickers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ describe('ClickersService', () => {
expect(clickedClicker.getCount()).toEqual(1);
});

it('loads empty list if given no argument', (done: Function) => {
clickers['initIds'](false)
.then((ids: Array<string>) => {
expect(ids).toEqual([]);
done();
});
});

it('loads IDs from storage', (done: Function) => {
clickers['initIds']()
.then((ids: Array<string>) => {
Expand Down
4 changes: 2 additions & 2 deletions src/services/clickers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ export class ClickersService {
}

// initialise Ids from SQL storage
private initIds(): Promise<{}> {
private initIds(load = true): Promise<{}> {
return this.storage.get('ids') // return the promise so we can chain initClickers
.then((rawIds: string) => {
if (!rawIds) return [];
if (!rawIds || !load) return [];
// ids are stored as stringified JSON array
return JSON.parse(rawIds);
});
Expand Down
2 changes: 1 addition & 1 deletion src/services/storage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let storage: StorageService = null;
describe('StorageService', () => {

beforeEach(() => {
spyOn(StorageService, 'initStorage').and.returnValue(new StorageMock());
// spyOn(StorageService, 'initStorage').and.returnValue(new StorageMock());
storage = new StorageService();
spyOn(storage['storage'], 'get').and.callThrough();
spyOn(storage['storage'], 'set').and.callThrough();
Expand Down
4 changes: 4 additions & 0 deletions typings/cordova-typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

/// <reference path="../.vscode/typings/cordova/cordova.d.ts"/>
/// <reference path="../.vscode/typings/cordova-ionic/plugins/keyboard.d.ts"/>
/// <reference path="../.vscode/typings/jquery/jquery.d.ts"/>

0 comments on commit 3e2551f

Please sign in to comment.