Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.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
Angular 如何在角度可观测订阅中对代码进行单元测试_Angular_Karma Jasmine - Fatal编程技术网

Angular 如何在角度可观测订阅中对代码进行单元测试

Angular 如何在角度可观测订阅中对代码进行单元测试,angular,karma-jasmine,Angular,Karma Jasmine,我正在为observable订阅中的代码编写一个单元测试用例,如下所示。但是这个测试失败了。有人能指出我这里的错误吗 ****组件技术**** this.myService.myData$.pipe(takeUntil(this.destroy)).subscribe(data=>{ if (this.oldValue !== this.currentValue) { callThisFunction(data); } }) ****单元测试用例***** 将myServiceM

我正在为observable订阅中的代码编写一个单元测试用例,如下所示。但是这个测试失败了。有人能指出我这里的错误吗

****组件技术****

this.myService.myData$.pipe(takeUntil(this.destroy)).subscribe(data=>{
 if (this.oldValue !== this.currentValue) {
  callThisFunction(data); 
}
})
****单元测试用例***** 将myServiceMock指定为在测试床中为myService提供useValue

 myServiceMock = {
       myValue: 'value'
       myData$: of([{a: 'name', b: 'age'}]) 
    }

it('test my data', done => {
        const myFuncStub = sinon.stub(component, 'callThisFunction');
        component.oldValue = 'x';
        component.myData$.subscribe(item => {
          expect(myFuncStub).to.have.been.called;
          done();
        });
      });