gpt4 book ai didi

unit-testing - Angular 2 单元测试 : Custom Pipe error The pipe could not be found

转载 作者:太空狗 更新时间:2023-10-29 16:51:42 27 4
gpt4 key购买 nike

我有一个名为“myPipe”的自定义管道。我得到:

The pipe 'myPipe' could not be found error

在我的单元测试中请建议在我的 .spec.ts 中导入和声明什么

这是我的.spec.ts

import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';

import { MyComponent } from './main-page-carousel.component';

describe('CarouselComponent', () => {
let component: MyComponent ;
let fixture: ComponentFixture<MyComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ MyComponent ],
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(MyComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});

谢谢!

最佳答案

你应该能够做到这一点:

import { MyPipe } from 'here put your custom pipe path';

TestBed.configureTestingModule({
declarations: [ MyComponentUnderTesting, MyPipe ]
})

关于unit-testing - Angular 2 单元测试 : Custom Pipe error The pipe could not be found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41543374/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com