首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在mat selectionChange上清除输入场的公空法的角单元试验

在mat selectionChange上清除输入场的公空法的角单元试验
EN

Stack Overflow用户
提问于 2021-01-26 05:04:59
回答 1查看 276关注 0票数 0

我对这项工作和编程很陌生,我的任务是进行单元测试,并获得80 %的代码覆盖率。我无法获得此方法的代码覆盖率。它说声明没有包括在内。我做错了什么?

support.component.ts

代码语言:javascript
复制
searchId: string = '';

orchestration: string = '';


public clearText(){

this.searchId = '';
this.orchestration = '';

}

support.component.html

代码语言:javascript
复制
<mat-select id="searchselected" (selectionChange)="clearText()">

<input type="text" class="form-control" id="searchId" [(ngModel)]=""searchId size="40" placeholder="enter value">
<input type="text" class="form-control" id="orchestration" [(ngModel)]=""searchId size="40" placeholder="enter orchestration">

support.component.spec.ts

代码语言:javascript
复制
const spy = spy = spyon(component, 'clearText').and.callThrough();

component.searchId;
component.orchestration;


component.clearText();

expect(spy).toHaveBeenCalled();
expect(component.searchId).toEqual('');
expect(component.orechestion).toEqual('');
EN

回答 1

Stack Overflow用户

发布于 2021-01-26 06:02:15

您不需要spyOn组件方法。外部方法(如服务方法)被监视,以避免在测试组件的方法时调用它们。

因此,您可以在这里直接调用该方法并测试以下条件:

support.component.spec.ts

代码语言:javascript
复制
component.clearText();
expect(component.searchId).toEqual('');
expect(component.orechestion).toEqual('');
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65896157

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档