ngx-translate 如何测试组件 [英] ngx-translate how to test components

查看:43
本文介绍了ngx-translate 如何测试组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用这个库的应用程序.我如何用它测试组件?我不想测试库.我只需要开始测试我的组件,而不会出现关于 TranslateModule 然后 TranslateService 然后 TranslateStore 的多个错误......直到我在编译时出现错误.

I've got an application which uses this library. How do I test components with it? I DO NOT WANT TO TEST THE LIBRARY. I just need to start tests of my component without multiple errors about TranslateModule then TranslateService then TranslateStore ... until I get an error when compiling.

是否有一种简单的方法可以使用此依赖项运行我的测试?

Is there an easy way to just run my tests with this dependency?

再说一次,我不想测试这个库(检查字符串是否被翻译)我需要对依赖这个库的组件运行测试.

Once more, I don't want to test this library (check whether the string is being translated) I need to run tests on components which rely on this library.

推荐答案

如果您不一定需要翻译键,您可以像这样在测试中导入 TranslateModule :

If you don't necessarily need the keys to be translated you can import the TranslateModule in your test like this:

beforeEach(async(() => {
  TestBed.configureTestingModule({
    declarations: [
      ...
    ],
    imports: [
      TranslateModule.forRoot(),
    ],
    providers: [
      ...
    ]
  })
  .compileComponents();
}));

它只会显示翻译键

这篇关于ngx-translate 如何测试组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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