问题描述
我是 Angular 2 测试的新手.我试图弄清楚在测试级别使用 testsbed.get()
和仅使用 inject
有什么区别.
例如:
beforeEach(() => {TestBed.configureTestingModule({提供者:[SomeService]});常量测试床 = getTestBed();someService= testbed.get(SomeService);});});
对
it('test service', inject([SomeService], (someService: SomeService) => {
只是添加到现有的答案,如果你像我一样发现这个问题,因为你想知道 TestBed.get() 和
TestBed.inject()
我知道这不是 OP 最初要求的,但它是相关的并且非常相关.
根据最新的 Angular 文档,我认为值得发布 TestBed.inject()
是 TestBed.get()
的类型安全替换.p>
来自 TestBed
的 Angular 文档,可以在
I am new to Angular 2 testing. I am trying to figure out what is the difference in using testsbed.get()
and just using inject
at the test level.
eg:
beforeEach(() => {
TestBed.configureTestingModule({
providers: [SomeService]
});
const testbed = getTestBed();
someService= testbed.get(SomeService);
});
});
vs
it('test service', inject([SomeService], (someService: SomeService) => {
Just to add to the existing answer and if like me you found this question because you are wondering what the difference is between TestBed.get()
and TestBed.inject()
which I know was not quite what the OP originally asked but it is relevant and is very much related.
I thought it was worth posting that according to the latest Angular documentation that TestBed.inject()
is the type safe replacement of TestBed.get()
.
From the Angular documentation on TestBed
that can be found here.
这篇关于Angular 2/Jasmine 测试中的 testbed.get 和 inject 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!