如何解决用管道测试角度分量
我尝试测试一个组件,但是模板中包含了cutom管道
component.html :
<ul class="test">
<li class="test1">{{'LABEL_TEST_PIPE' | translateLabels }}</li>
</ul>
component.spec.ts
describe('Component',() => {
let fixture: ComponentFixture<Component>;
beforeEach(async () => {
TestBed.configureTestingModule({
declarations: [ Component ],imports: [ TranslateLabelsPipe ]
});
});
test('should be translate',() => {
fixture = TestBed.createComponent(Component);
const component = fixture.componentInstance;
fixture.detectChanges();
const element = fixture.debugElement;
expect(element.nativeElement.querySelector('li').textContent).toContain('test pipe translate');
});
});
我的终端中有这个
Test Suites: 0 failed,0 of 1 total
Tests: 0 total
Snapshots: 0 total
Time: 284 s
我必须使用Ctrl + C停止它,否则它将永远不会停止... 当我取下管道时,我的测试会自动停止。 我试图对其进行嘲笑,但它也不起作用。
有人有主意吗?
谢谢
解决方法
您可以使用以下方法来模拟管道:https://stackoverflow.com/a/41826482/7365461,但是主要问题是将管道放置在imports
数组中,而不是declarations
。
尝试将管道移动到declarations
数组。
感谢您的回答。
当我在declarations
数组中移动管道时,我遇到了同样的问题,测试永远不会停止。
我的应用程序中有很多组件,不能为每个测试模拟管道。
必须有某种方法来集成或导入自定义管道...:/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。