angular - 使用 matHorizontalStepper 进行测试。角材料
问题描述
我正在为垫子步进器编写测试。我遇到了错误:错误:找不到名称“matHorizontalStepper”的导出!
感谢下面的评论,我想通了。
当使用 Angular Material 组件进行测试时,您必须将它们与 BrowserAnimationsModule 和有时 ReactiveFormsModule 一起导入到您的测试文件中。
describe('EditFulfillmentWorkflowComponent', () => {
let component: EditFulfillmentWorkflowComponent;
let fixture: ComponentFixture<EditFulfillmentWorkflowComponent>;
beforeEach(() => {
const activatedRouteStub = () => ({
snapshot: { paramMap: { get: () => ({}) } }
});
const routerStub = () => ({ navigateByUrl: string => ({}) });
const notificationsServiceStub = () => ({});
const fulfillmentServiceStub = () => ({
getFulfillmentWorkflows: any => ({ subscribe: f => f }),
getOrchestratorActionInfo: any => ({ subscribe: f => f }),
checkIfWorkflowNameExists: any => ({ subscribe: f => f(Boolean) }),
updateFulfillmentWorkflow: submitFulfillmentWorkflow => ({
subscribe: f => f({})
})
});
TestBed.configureTestingModule({
schemas: [NO_ERRORS_SCHEMA],
declarations: [EditFulfillmentWorkflowComponent],
imports: [MatStepperModule, BrowserAnimationsModule, ReactiveFormsModule],
providers: [
{ provide: ActivatedRoute, useFactory: activatedRouteStub },
{ provide: Router, useFactory: routerStub },
{ provide: NotificationsService, useFactory: notificationsServiceStub },
{ provide: FulfillmentService, useFactory: fulfillmentServiceStub }
]
});
fixture = TestBed.createComponent(EditFulfillmentWorkflowComponent);
component = fixture.componentInstance;
});
beforeEach(() => {
fixture = TestBed.createComponent(EditFulfillmentWorkflowComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
[编辑]第一条评论解决了我的问题。
解决方案
首先,您需要导入组件使用的所有模块。
因此,您需要导入:
import {MatStepperModule} from '@angular/material/stepper';
并将其添加imports
到TestBed.configureTestingModule({...})
此外,如果您在组件中使用组件,则需要declarations: [EditFulfillmentWorkflowComponent],
添加TestBed.configureTestingModule({...})
推荐阅读
- docker - 对链接到 docker repo (0x Launch Kit) 的前端 repo 进行更改
- ios - Flutter 找不到 FirebaseCore.h
- python - 以灵活的方式更改 Pandas Python 中的多个值
- python - 使用 ProcessPoolExecutor 在进程之间共享谷歌云存储客户端
- cordova - 断言:动画时应该调用 _before()
- typescript - 基于传递的布尔参数的返回类型
- bigcommerce - Bigcommerce 是否可以将所有 bigcommerce 文件拉到本地环境中,以便我可以在本地测试更改?
- c++ - 为什么我们不能将 char 分配给字符串?
- hamiltonian-cycle - 使用 LKH-2,是否可以提取所有哈密顿循环?
- git - 在重新调整其分支后重新打开关闭的拉取请求