angular2 testing using jasmine for subscribe method

前端 未结 4 1501
慢半拍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:07

    You need to mock the login function as follows:

    let loginService: any = {
        login(): Observable {
            return Observable.of('you object');
        }
    };
    

    you might find the observable.if function undefined, so you need to import the observable this way:

    import { Observable } from 'rxjs/Rx';
    import 'rxjs/add/observable/of';
    

提交回复
热议问题