私は最初のIonicアプリを構築しており、TDDに従うことを頑張っています。私は、Ionicが提供しているPlatform.readyの約束を抱いてぶつかり合った。私は、私の人生のために、テスト中にそれを引き起こす方法を理解することはできません。イオンのデモでは、initializeApp
このような関数に表示されます:私はstatusBar
のstyleDefault
メソッドが呼び出されているかどうかをチェックしています簡単なテストでIonicのPlatform.readyをテストする方法を教えてください。
initializeApp() {
this.platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
this.statusBar.styleDefault();
this.splashScreen.hide();
});
}
が、私はトリガーする方法を把握するためには至っていません解決するにはplatform.ready
編集:テストファイル全体が含まれているかどうかについての質問を止めるために。
import { async, TestBed } from '@angular/core/testing';
import { IonicModule } from 'ionic-angular';
import { MyApp } from './app.component';
import { SplashScreenMock as SplashScreen, StatusBarMock as StatusBar, PlatformMock as Platform } from '../../test-config/mocks-ionic';
import { LoginPageMock as LoginPage } from "../../test-config/custom-mocks/login.mock"
describe('App Component',() => {
let fixture, component, SB;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations:[MyApp, LoginPage],
imports: [IonicModule.forRoot(MyApp)],
providers :[StatusBar, SplashScreen, Platform]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(MyApp);
SB = TestBed.get(StatusBar);
spyOn(SB, 'styleDefault').and.callThrough();
component = fixture.componentInstance;
});
describe('general status before initialization',() => {
it('should be defined',() => {
expect(component).toBeDefined();
});
it('should be created',() => {
expect(component instanceof MyApp).toBe(true);
});
it('should have a populated pages array',() => {
expect(component.pages.length).toBeGreaterThan(0);
});
});
describe('general status after initialization',() => {
it('should style the statusbar when the app is initialized', async((done) => {
component.initializeApp();
expect(SB.styleDefault).toHaveBeenCalled();
done();
}));
});
});
私はおそらく間違ってそれを保持しています、または多分私が持っていますかわからないが、この時点で私が間違って何であるか見当がつかない。任意のオプションとすべてのオプションが考慮され、すべてのサポートが評価されます。
注:はい、私はfixture.detectChanges()
および/またはfixture.autoDetectChanges(true)
を入力しようとしましたが、未処理の約束拒否とLoginPageのコンポーネント要素が見つかりませんでした。私はまだそのエラーに対処しようとしていますが、それが約束を解決することと関係があるかどうかはわかりません。あなたがこの小さな問題の解決策を持っていれば、私もそれを見てうれしいです。
申し訳ありませんが、これは役に立たず、約束を解決する方法の主な質問トピックは扱いません。通常は 'done'を渡してからそれを呼び出すのですが、何らかの理由でこれをやっていないのです。 – MBielski
あなたはbeforeEachにasyncを持っていますか? fixture.detectChanges()? – JGFMK
テスト設定の大部分を除外していますが、それは無関係ですが、はい、私のbeforeEachはあなたのものに非常によく似ています。 fixture.detectChangesを使用するのは、UIの変更を確認するためのものです。これは私がやろうとしていることではありません。私はこのメソッド呼び出しを検出することができます私は他人を検出することができますし、私のアプリが正常に動作していることを知っているが、私はこの1つを検出することはできません。 – MBielski