订阅块中的代码未在单元测试角度2

时间:2018-04-23 12:56:12

标签: angular jasmine

我有一个名为X()的服务

我的构造函数

constructor(private http: ApiService) { }

其中ApiService扩展了Http。

在我的spec文件中,我有一个测试

x.xx(payload).subscribe(() => {
          alert("Hi");
        });

此警报未执行,测试处于异步模式。

如果我将构造函数更改为

    constructor(private http: Http) { }

它有效。

我尝试了什么?

  1. 使用提供程序用Http [not working]

    替换ApiService

    提供者:[           {provide:ApiService,useClass:Http},]

  2. 2.手动更改私人变量[不工作]

    x['http']=Http
    

    *******************更新*************************** *****************

    https://github.com/astronaut1712/ng2-http-intercept/blob/master/src/intercept.http.service.ts这是APIService

0 个答案:

没有答案