unit testing - How to mock DialogService.open(...).whenClosed(...) with Jasmine? -
we have typescript code using aurelia framework , dialog plugin trying test jasmine, can't work out how properly.
this source function:
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; } } }); } we can create dialogservice spy, , verify open method - can't work out how make spy invoke whenclosed method mocked result parameter can assert step completed.
this current jasmine code:
it("opens dialog when clicking on incomplete bank account", async done => { // arrange arrangememberverificationstatus(); await component.create(bootstrap); const vm = component.viewmodel 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(); });
wiki
Comments
Post a Comment