Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
836 views
in Technique[技术] by (71.8m points)

angular - NG2 RC5: HTTP_PROVIDERS is deprecated

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.

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....", () => { ... });
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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
        ...
    })
})

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...