Skip to content

Commit f7d45bc

Browse files
authored
Merge pull request #29 from driftyco/chore/fixes-after-merges
Chore/fixes after merges
2 parents 3ff57ce + b199532 commit f7d45bc

File tree

3 files changed

+73
-5
lines changed

3 files changed

+73
-5
lines changed

src/app/app.component.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { async, TestBed } from '@angular/core/testing';
2-
import { IonicModule } from 'ionic-angular';
2+
import { IonicModule, Platform } from 'ionic-angular';
33

44
import { StatusBar } from '@ionic-native/status-bar';
55
import { SplashScreen } from '@ionic-native/splash-screen';
66

77
import { MyApp } from './app.component';
8+
import { PlatformMock } from '../../test-config/mocks-ionic';
89

910
describe('MyApp Component', () => {
1011
let fixture;
@@ -18,7 +19,8 @@ describe('MyApp Component', () => {
1819
],
1920
providers: [
2021
StatusBar,
21-
SplashScreen
22+
SplashScreen,
23+
{ provide: Platform, useClass: PlatformMock }
2224
]
2325
})
2426
}));

src/pages/page1/page1.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
22
import { By } from '@angular/platform-browser';
33
import { DebugElement } from '@angular/core';
4-
import { Page1 } from "./page1";
5-
import { IonicModule, NavController } from "ionic-angular/index";
4+
import { Page1 } from './page1';
5+
import { IonicModule, Platform, NavController } from 'ionic-angular/index';
6+
import { PlatformMock } from '../../../test-config/mocks-ionic';
67

78
describe('Page1', function () {
89
let de: DebugElement;
@@ -16,7 +17,8 @@ describe('Page1', function () {
1617
IonicModule.forRoot(Page1)
1718
],
1819
providers: [
19-
NavController
20+
NavController,
21+
{ provide: Platform, useClass: PlatformMock}
2022
]
2123
});
2224
}));

test-config/mocks-ionic.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
export class PlatformMock {
2+
public ready(): Promise<{String}> {
3+
return new Promise((resolve) => {
4+
resolve('READY');
5+
});
6+
}
7+
8+
public getQueryParam() {
9+
return true;
10+
}
11+
12+
public registerBackButtonAction(fn: Function, priority?: number): Function {
13+
return (() => true);
14+
}
15+
16+
public hasFocus(ele: HTMLElement): boolean {
17+
return true;
18+
}
19+
20+
public doc(): HTMLDocument {
21+
return document;
22+
}
23+
24+
public is(): boolean {
25+
return true;
26+
}
27+
28+
public getElementComputedStyle(container: any): any {
29+
return {
30+
paddingLeft: '10',
31+
paddingTop: '10',
32+
paddingRight: '10',
33+
paddingBottom: '10',
34+
};
35+
}
36+
37+
public onResize(callback: any) {
38+
return callback;
39+
}
40+
41+
public registerListener(ele: any, eventName: string, callback: any): Function {
42+
return (() => true);
43+
}
44+
45+
public win(): Window {
46+
return window;
47+
}
48+
49+
public raf(callback: any): number {
50+
return 1;
51+
}
52+
53+
public timeout(callback: any, timer: number): any {
54+
return setTimeout(callback, timer);
55+
}
56+
57+
public cancelTimeout(id: any) {
58+
// do nothing
59+
}
60+
61+
public getActiveElement(): any {
62+
return document['activeElement'];
63+
}
64+
}

0 commit comments

Comments
 (0)