【问题标题】:get of Map<string,string> not a function in Angualr Testing获取 Map<string,string> 不是 Angular 测试中的函数
【发布时间】:2020-02-14 11:12:22
【问题描述】:

角度测试抛出 TypeError: _co.mapNumbers.get is not a function 在与 Karma 一起运行的测试中。组件工作正常,代码如下:

在我声明的组件中:

export class A{
     mapNumbers:Map<string,string>;
     ngOnInit() {
       mapNumbers = JSONOBJECT[0] // Assignment of values works fine and also matches the type
}

在模板中:

<span>
          {{mapNumbers.get('24_HOURS_ASSISTANCE_PHONE_NUMBER')
            ) | translate
          }}
        </span>

这并不复杂,但似乎对 Karma 不起作用,我需要在这里对 Map 进行特殊导入吗?

【问题讨论】:

    标签: angular unit-testing testing karma-jasmine


    【解决方案1】:

    这很奇怪,但似乎除非我使用 Map 的 set 方法直接分配只适用于应用程序,但不适用于单元测试:

    arrayOutput = new Map();
    
    arrayInput.foreach((value: string, key: string) => {
            this.arryOutput.set(key,value);  // Unit test fails unless assing the values through set method
        });
    

    【讨论】:

      猜你喜欢
      • 2015-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-06
      • 1970-01-01
      • 2019-06-29
      • 1970-01-01
      • 2023-02-24
      相关资源
      最近更新 更多