- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在使用 angular2 进行组件测试。 在我的 html 模板中,我使用了翻译管道。 这是测试代码:
import { ComponentFixture, TestBed ,getTestBed} from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { RightComponent } from './right.component';
import {TranslateService} from 'ng2-translate/ng2-translate';
import {Injector} from "@angular/core";
let comp: RightComponent;
let fixture: ComponentFixture<RightComponent>;
let el: DebugElement;
let translate: TranslateService;
let injector: Injector;
describe('testComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [ RightComponent ]
});
injector = getTestBed();
translate = injector.get(TranslateService);
fixture = TestBed.createComponent(RightComponent);
comp = fixture.componentInstance; // BannerComponent test instance
// get title DebugElement by element name
el = fixture.debugElement.query(By.css('h2'));
});
it('should display original title', () => {
fixture.detectChanges(); // trigger data binding
expect(el.nativeElement.textContent).toContain('Liste des droits');
});
});
我收到此错误,因为翻译管道未知:
Error: Template parse errors:
The pipe 'translate' could not be found ("<h2>[ERROR ->]{{'RIGHT_TITLE' | translate}}</h2>
<div class="table-responsive">
<table id="rightTableId" clas"): RightComponent@0:4
The pipe 'translate' could not be found ("
<table id="rightTableId" class="table table-striped">
<tr>
<th>[ERROR ->]{{'NAME_LABEL' | translate}}</th>
</tr>
<tr *ngFor="let right of rights">
"): RightComponent@4:16
The pipe 'translate' could not be found ("
</tr>
<tr *ngFor="let right of rights">
<td>[ERROR ->]{{right.name | translate}}</td>
</tr>
</table>
我们如何解决这个问题?
谢谢。
最佳答案
it's the ng2-translate github.com/ocombe/ng2-translate
您需要使用库模块配置TestBed
,就像您使用实际应用程序配置库一样。看着 documentation , 它显示通过导入模块配置它
imports: [
TranslateModule.forRoot()
]
所以你应该在 TestBed
配置中做同样的事情
TestBed.configureTestingModule({
declarations: [ RightComponent ],
imports: [TranslateModule.forRoot()]
});
这就是 TestBed.configureTestingModule
的用途:为测试环境配置模块。
关于angular - 找不到管道 'translate',angular2 组件测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39597952/
例如,我有一个父类Author: class Author { String name static hasMany = [ fiction: Book,
代码如下: dojo.query(subNav.navClass).forEach(function(node, index, arr){ if(dojo.style(node, 'd
我有一个带有 Id 和姓名的学生表和一个带有 Id 和 friend Id 的 Friends 表。我想加入这两个表并找到学生的 friend 。 例如,Ashley 的 friend 是 Saman
我通过互联网浏览,但仍未找到问题的答案。应该很容易: class Parent { String name Child child } 当我有一个 child 对象时,如何获得它的 paren
我正在尝试创建一个以 Firebase 作为我的后端的社交应用。现在我正面临如何(在哪里?)找到 friend 功能的问题。 我有每个用户的邮件地址。 我可以访问用户的电话也预订。 在传统的后端中,我
我主要想澄清以下几点: 1。有人告诉我,在 iOS 5 及以下版本中,如果您使用 Game Center 设置多人游戏,则“查找 Facebook 好友”(如与好友争夺战)的功能不是内置的,因此您需要
关于redis docker镜像ENTRYPOINT脚本 docker-entrypoint.sh : #!/bin/sh set -e # first arg is `-f` or `--some-
我是一名优秀的程序员,十分优秀!