Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.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
Jasmine 建议代码覆盖率的角度单元测试_Jasmine_Angular Unit Test - Fatal编程技术网

Jasmine 建议代码覆盖率的角度单元测试

Jasmine 建议代码覆盖率的角度单元测试,jasmine,angular-unit-test,Jasmine,Angular Unit Test,请建议对上述代码进行单元测试。太好了,先生。解释得很好。我会用这个来投票,很好,先生。解释得很好。我将使用这个,并将投票表决这个答案。 async ngOnInit() { if (localStorage.getItem('Authorization') && this.formdataservice.get_account_user_id()) { try { let res: any = await this.formdataservic

请建议对上述代码进行单元测试。

太好了,先生。解释得很好。我会用这个来投票,很好,先生。解释得很好。我将使用这个,并将投票表决这个答案。
async ngOnInit() {
    if (localStorage.getItem('Authorization') && this.formdataservice.get_account_user_id()) {
      try {
        let res: any = await this.formdataservice.get_preferences().toPromise();
        const { data } = res.body;
        this.formdataservice.set_preferences(data);
      } catch (e) {}
    }
  }
it('should call set_preferences if Authorization is set in local storage and acount_user_id is populated', async(done) => {
  // arrange => you will have to set Authorization in local storage before the first detect changes in the beforeEach block because that's when `ngOnInit` is called. Also, mock formDataService.get_Acount_user_id() to return a truthy value;
 // also have to mock `get_preferences()` to return a promise for res;
 // wait for promises to finish
  await fixture.whenStable(); // this waits for promises to finish
 // assert => expect `set_preferences()` toHaveBeenCalledWith whatever data is. 
  done(); 
});