Angular 如何在角度可观测订阅中对代码进行单元测试
我正在为observable订阅中的代码编写一个单元测试用例,如下所示。但是这个测试失败了。有人能指出我这里的错误吗 ****组件技术****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
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();
});
});