【发布时间】:2020-04-04 16:48:38
【问题描述】:
如何使用 jasmine 覆盖下面函数的所有行?
addUser(): void {
if (this.validateNewUser()) {
this.newUser._Job = this.selectedJob;
this.newUser.PositionId = this.selectedJob.Id;
this.newUser.Position = this.selectedJob.Value;
this.newUser._Area = this.selectedArea;
this.newUser.AreaId = this.selectedArea.Id;
this.newUser.Area = this.selectedArea.Value;
this.users.push(this.newUser);
this.clear();
this.toastService.open('Usuário incluído com sucesso!', { type: 'success', close: true });
}
}
我目前正在尝试如下,但没有考虑覆盖任何行:
it('Given_addUser_When_UserStepIsCalled_Then_ExpectToBeCalled', (done) => {
component.addUser = jasmine.createSpy();
component.addUser();
expect(component.addUser).toHaveBeenCalled();
done();
});
已编辑
现在: Image here
【问题讨论】:
标签: jasmine karma-jasmine karma-coverage jasmine2.0