我正在开发一个新项目,并将使用CLI生成应用程序和所有文件,但是我遇到了一些似乎对我和我都很不好的东西希望有一个更好的方法来做到这一点。Angular 2 CLI如何在所有规格中轻松包含RouterTestingModule
我的应用程序有路由,所以在我的测试中,我需要导入RouterTestingModule
为路由器提供模拟。但是,由于我们创建的每个规范都需要这个,所以如果在创建新组件时默认包含它,那将会非常好。我研究了对自定义蓝图的支持,但目前还没有任何支持,这是一个无赖,因为如果我可以将该模块添加到蓝图中,这将非常简单。
有什么其他选项可以默认包含在所有规格中,而不需要每个开发人员在创建新组件时都记得添加它?
describe('LoginComponent',() => {
let component: LoginComponent;
let fixture: ComponentFixture<LoginComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ LoginComponent ],
imports: [
RouterTestingModule, // I don't want to have to manually add this in every spec file.
SharedModule
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(LoginComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create',() => {
expect(component).toBeTruthy();
});
});
模块上你所有的可重复使用的进口创建和它包括在这里。 –
我这样做了,我在'SharedModule'内包含'RouterModule'的实际导入,你会看到我在导入规范。问题是在测试中我需要导入'RouterTestingModule'而不是'RouterModule'来让测试运行。 – efarley
好吧,它似乎不会伤害任何东西,包括'RouterTestingModule'到应用程序,而不是只包括它在规格。 – efarley