Unit testing an observable in Angular 2

后端 未结 6 1938
灰色年华
灰色年华 2020-12-24 10:17

What is the correct way of unit testing a service returning an Observable result in Angular 2? Let\'s say we have a getCars method in a CarService service class:

<         


        
6条回答
  •  一整个雨季
    2020-12-24 11:01

    The way I've managed to get it to work is to subscribe and call done after the expects.

    it('should equal bar', (done: any) => {
     bar.getFoo().subscribe(v => {
      expect(v).toBe('foo');
      done();
     });
    });
    

提交回复
热议问题