Skip to content

Instantly share code, notes, and snippets.

@leifwells
Created September 2, 2017 16:23
Show Gist options
  • Select an option

  • Save leifwells/d2f5f442dcbd9617f2e3f0572db5ea76 to your computer and use it in GitHub Desktop.

Select an option

Save leifwells/d2f5f442dcbd9617f2e3f0572db5ea76 to your computer and use it in GitHub Desktop.
Starter unit test for app.component.ts for an Ionic project
import { async, TestBed } from '@angular/core/testing';
import { IonicModule, Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { MyApp } from './app.component';
import {
PlatformMock,
StatusBarMock,
SplashScreenMock
} from '../../test-config/mocks-ionic';
describe('MyApp Component', () => {
let fixture;
let component;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [MyApp],
imports: [
IonicModule.forRoot(MyApp)
],
providers: [
{ provide: StatusBar, useClass: StatusBarMock },
{ provide: SplashScreen, useClass: SplashScreenMock },
{ provide: Platform, useClass: PlatformMock }
]
})
}));
beforeEach(() => {
fixture = TestBed.createComponent(MyApp);
component = fixture.componentInstance;
});
it('should be created', () => {
expect(component instanceof MyApp).toBe(true);
});
it('should have two pages', () => {
expect(component.pages.length).toBe(2);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment