我试图测试一个组件,但在模板中使用了割接管道
component.html:
<ul class="test">
<li class="test1">{{'LABEL_TEST_PIPE' | translateLabels }}</li>
</ul>
组件规范
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
阵列。