【发布时间】:2018-02-23 04:43:23
【问题描述】:
在How to globally set the preserveWhitespaces option in Angular to false? 之后,我将我的配置设置为全局禁用空白保留,但是当我运行我的测试时,这不符合要求。
如何为测试设置这个。我尝试手动配置tsconfig.spec.json,但没有积极效果。
【问题讨论】:
标签: angular
在How to globally set the preserveWhitespaces option in Angular to false? 之后,我将我的配置设置为全局禁用空白保留,但是当我运行我的测试时,这不符合要求。
如何为测试设置这个。我尝试手动配置tsconfig.spec.json,但没有积极效果。
【问题讨论】:
标签: angular
抱歉耽搁了(好像我错过了你对我之前的answer的评论)
使用 Jit 编译器运行测试,因此在 tsconfig 上设置选项不会有任何影响。
我们可以在TestBed 上使用configureCompiler 方法。由于此方法的签名不支持preserveWhitespases 选项,我们必须将选项转换为any。
这是它的样子:
app.component.spec.ts
beforeEach(async(() => {
TestBed.configureCompiler({ preserveWhitespaces: false } as any)
.configureTestingModule({
declarations: [
AppComponent
],
}).compileComponents();
}));
【讨论】: