Jasmine でテストしようとしている Aurelia フレームワークと Dialog プラグインを使用する TypeScript コードがいくつかありますが、適切に実行する方法がわかりません。
これはソース関数です:
openDialog(action: string) {
this._dialogService.open({ viewModel: AddAccountWizard })
.whenClosed(result => {
if (!result.wasCancelled && result.output) {
const step = this.steps.find((i) => i.action === action);
if (step) {
step.isCompleted = true;
}
}
});
}
DialogService スパイを作成し、open メソッドを簡単に検証できます。ただし、モック化された結果パラメーターを使用してスパイに whenClosed メソッドを呼び出させ、ステップが完了したことをアサートできるようにする方法がわかりません。
これは現在の Jasmine コードです。
it("opens a dialog when clicking on incomplete bank account", async done => {
// arrange
arrangeMemberVerificationStatus();
await component.create(bootstrap);
const vm = component.viewModel as GettingStartedCustomElement;
dialogService.open.and.callFake(() => {
return { whenClosed: () => Promise.resolve({})};
});
// act
$(".link, .-arrow")[0].click();
// assert
expect(dialogService.open).toHaveBeenCalledWith({ viewModel: AddAccountWizard });
expect(vm.steps[2].isCompleted).toBeTruthy(); // FAILS
done();
});