【问题标题】:Angular set preserveWhitespace in karma tests业力测试中的角度设置 preserveWhitespace
【发布时间】:2018-02-23 04:43:23
【问题描述】:

How to globally set the preserveWhitespaces option in Angular to false? 之后,我将我的配置设置为全局禁用空白保留,但是当我运行我的测试时,这不符合要求。

如何为测试设置这个。我尝试手动配置tsconfig.spec.json,但没有积极效果。

【问题讨论】:

    标签: angular


    【解决方案1】:

    抱歉耽搁了(好像我错过了你对我之前的answer的评论)

    使用 Jit 编译器运行测试,因此在 tsconfig 上设置选项不会有任何影响。

    我们可以在TestBed 上使用configureCompiler 方法。由于此方法的签名不支持preserveWhitespases 选项,我们必须将选项转换为any

    这是它的样子:

    app.component.spec.ts

    beforeEach(async(() => {
       TestBed.configureCompiler({ preserveWhitespaces: false } as any)
         .configureTestingModule({
           declarations: [
             AppComponent
           ],
         }).compileComponents();
    }));
    

    【讨论】:

      猜你喜欢
      • 2020-08-06
      • 2014-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-23
      • 2020-02-24
      • 1970-01-01
      • 2019-05-07
      相关资源
      最近更新 更多