我有一个定制的管道,叫做“我的管道”。我得到了:
找不到管道'myPipe‘错误
在我的单元测试中。请建议在我的.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();
});
});
谢谢!
发布于 2017-08-03 17:13:42
你应该能够做到这一点:
import { MyPipe } from 'here put your custom pipe path';
TestBed.configureTestingModule({
declarations: [ MyComponentUnderTesting, MyPipe ]
})
发布于 2017-06-12 21:30:52
我也遇到了同样的问题,并通过在我的spec.ts中添加以下“模拟管道”来修复它:
import {Pipe, PipeTransform} from '@angular/core';
@Pipe({name: 'myPipe'})
class MockPipe implements PipeTransform {
transform(value: number): number {
// blah blah
return value;
}
}
然后,必须将MockPipe添加到TestBed configureTestingModule声明中:
TestBed.configureTestingModule({
declarations: [ MyComponentUnderTesting, MockPipe ]
})
发布于 2020-03-24 16:59:03
我遇到了几乎相同的管道问题;在模板解析错误的情况下,您需要执行两个步骤:
import {{ your_pipe_name }} from '../your/pipe/location'
;TestBed.configureTestingModule({ declarations: [ your_pipe ] });
编码愉快!
https://stackoverflow.com/questions/41543374
复制相似问题