app.component.spec.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
  2. import { TestBed, async } from '@angular/core/testing';
  3. import { Platform } from '@ionic/angular';
  4. import { SplashScreen } from '@ionic-native/splash-screen/ngx';
  5. import { StatusBar } from '@ionic-native/status-bar/ngx';
  6. import { AppComponent } from './app.component';
  7. describe('AppComponent', () => {
  8. let statusBarSpy;
  9. let splashScreenSpy;
  10. let platformReadySpy;
  11. let platformSpy;
  12. beforeEach(async(() => {
  13. statusBarSpy = jasmine.createSpyObj('StatusBar', ['styleDefault']);
  14. splashScreenSpy = jasmine.createSpyObj('SplashScreen', ['hide']);
  15. platformReadySpy = Promise.resolve();
  16. platformSpy = jasmine.createSpyObj('Platform', { ready: platformReadySpy });
  17. TestBed.configureTestingModule({
  18. declarations: [AppComponent],
  19. schemas: [CUSTOM_ELEMENTS_SCHEMA],
  20. providers: [
  21. { provide: StatusBar, useValue: statusBarSpy },
  22. { provide: SplashScreen, useValue: splashScreenSpy },
  23. { provide: Platform, useValue: platformSpy },
  24. ],
  25. }).compileComponents();
  26. }));
  27. it('should create the app', () => {
  28. const fixture = TestBed.createComponent(AppComponent);
  29. const app = fixture.debugElement.componentInstance;
  30. expect(app).toBeTruthy();
  31. });
  32. it('should initialize the app', async () => {
  33. TestBed.createComponent(AppComponent);
  34. expect(platformSpy.ready).toHaveBeenCalled();
  35. await platformReadySpy;
  36. expect(statusBarSpy.styleDefault).toHaveBeenCalled();
  37. expect(splashScreenSpy.hide).toHaveBeenCalled();
  38. });
  39. // TODO: add more tests!
  40. });