Angular 2/Jasmine 测试中的 testbed.get 和 inject 有什么区别? [英] What is the difference between testbed.get and inject in Angular 2/Jasmine testing?

查看:24
本文介绍了Angular 2/Jasmine 测试中的 testbed.get 和 inject 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Angular 2 测试的新手.我试图弄清楚在测试级别使用 testsbed.get() 和仅使用 inject 有什么区别.

例如:

beforeEach(() => {TestBed.configureTestingModule({提供者:[SomeService]});常量测试床 = getTestBed();someService= testbed.get(SomeService);});});

it('test service', inject([SomeService], (someService: SomeService) => {

解决方案

只是添加到现有的答案,如果你像我一样发现这个问题,因为你想知道 TestBed.get()<之间有什么区别/code> 和 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 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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