Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
单元测试If语句angular6_Angular_Unit Testing - Fatal编程技术网

单元测试If语句angular6

单元测试If语句angular6,angular,unit-testing,Angular,Unit Testing,我在angular6中有一个简单的if语句,我需要为它编写单元测试 ngOnInit(){ 如果(此.actionResult){ this.dataTable=JSON.parse(JSON.parse(this.actionResult)); this.dataSource=新MatTableDataSource(this.dataTable); this.dataSource.\u updateChangeSubscription(); } } 代码覆盖范围显示如果未采用

我在angular6中有一个简单的if语句,我需要为它编写单元测试

ngOnInit(){
如果(此.actionResult){
this.dataTable=JSON.parse(JSON.parse(this.actionResult));
this.dataSource=新MatTableDataSource(this.dataTable);
this.dataSource.\u updateChangeSubscription();
}        
}
代码覆盖范围显示
如果未采用路径
,我如何在规范中涵盖这一点


请帮助。

还有一些断言,如

  • dataTable
    toBeTruthy()/tobededefined()
  • 类似地,对于
    数据源
  • 方法
    \u updateChangeSubscription
    上的
    spy
    ,并希望已调用该方法
这一断言将使您的代码充分证明

请看我对其他问题的回答,以供参考