Angular2 - Unit testing Observable error “Cannot read property 'subscribe' of undefined”

不羁岁月 提交于 2019-12-05 10:11:42
Albert Pérez Farrés

When you spy a service method and expect to be called, you should add .and.callThrough() on spyOn.

Your code should be like this: spyOn(authServiceStub, 'register').and.callThrough();

And then, expect to haveBeenCalled().

Take a look at: http://blog.danieleghidoli.it/2016/11/06/testing-angular-component-mock-services/

Can you import this in your app.module or in your unit test

 import { Observable } from 'rxjs/Rx';
 import 'rxjs/Rx';
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!