angular2 testing using jasmine for subscribe method

前端 未结 4 1495
慢半拍i
慢半拍i 2020-12-29 05:21

I have a spec code to test like this

 it(\'login test\', () => {

      const fixture = TestBed.createComponent(component);
      fixture.detectChanges();         


        
4条回答
  •  长发绾君心
    2020-12-29 06:11

    You need to return something with a subscribe method, as the component calls subscribe directly from login. A string does not. You could just return an object with a subscribe function and it should work

    and.returnValue({ subscribe: () => {} });
    

    Or if you want to pass a real observable, you could

    and.returnValue(Observable.of('some value'));
    

    You might need to import rxjs/add/observable/of

提交回复
热议问题