NG2 RC5:不建议使用HTTP_PROVIDERS [英] NG2 RC5: HTTP_PROVIDERS is deprecated

查看:83
本文介绍了NG2 RC5:不建议使用HTTP_PROVIDERS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,在Angular2的RC5版本中,他们弃用了 HTTP_PROVIDERS 并引入了 HttpModule 。对于我的应用程序代码,这可以正常工作,但是我正努力在Jasmine测试中进行更改。

So, in version RC5 of Angular2, they deprecated the HTTP_PROVIDERS and introduced the HttpModule. For my application code, this is working fine, but I'm struggling to make the change in my Jasmine tests.

这是我目前在规范中所做的事情,但是由于不建议使用HTTP_PROVIDERS,我现在应该怎么做?我需要提供而不是HTTP_PROVIDERS吗?在RC5世界中,执行此操作的正确方法是什么?

Here's what I'm currently doing in my specs, but since HTTP_PROVIDERS is deprecated, what should I be doing now? Is there something I need to provide instead of HTTP_PROVIDERS? What is the correct way to do this in the RC5 world?

beforeEach(() => {
  reflectiveInjector = ReflectiveInjector.resolveAndCreate([
    HTTP_PROVIDERS,
    ...
  ]);

  //other code here...
});

it("should....", () => { ... });


推荐答案

现在不推荐使用的HTTP_PROVIDERS替换为HttpModule,即RC5 。

The now deprecated HTTP_PROVIDERS is replaced with the HttpModule is RC5.

在您的describe块中,添加具有必需的import和provider数组属性的TestBed.configureTestingModule,如下所示:

Within your describe block, add the TestBed.configureTestingModule with the requisite imports and providers array attributes like below:

describe("test description", () => {
    beforeEach(() => {
        TestBed.configureTestingModule({
            imports: [HttpModule],
            providers: [SomeService]
        });
    });
    it("expect something..", () => {
        // some expectation here
        ...
    })
})

这就是我让单元服务测试与RC5一起使用的方式,希望这不必在下一个发行候选版本和最终版本之间进行更改。如果您像我一样,您可能会对候选版本之间正在进行的弃用数量感到沮丧。我希望事情会很快稳定!

This is how I got my unit service tests to work with RC5, hopefully this won't have to change between the next release candidates and the final version. If you are like me, you are probably frustrated with the amount of deprecation that is going on between release candidates. I hope things stabilize soon!

这篇关于NG2 RC5:不建议使用HTTP_PROVIDERS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆