Juliyanage Silva
Juliyanage Silva

Reputation: 2699

get of Map<string,string> not a function in Angualr Testing

Angular testing throws TypeError: _co.mapNumbers.get is not a function in the test running with Karma. Component works fine and code is like below:

In component I have declared:

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

In template:

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

It's nothing complex but seems it does not work for Karma, Do I need to do a special import for Map here?

Upvotes: 1

Views: 490

Answers (1)

Juliyanage Silva
Juliyanage Silva

Reputation: 2699

It's strange but seems like unless I use Map's set method direct assigning only works with the app but not unit testing:

arrayOutput = new Map();

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

Upvotes: 2

Related Questions