[Vuejs]-How to solve toUpperCase issue in Jest testing?

3πŸ‘

βœ…

.toUpperCase() is a method provided by the String-class. It seems your variable this.checkDeliveryType isn’t a string, hence you can not call this method (as it does not exist on whatever type your variable is at that point in time).

Either fix the type or cast the value manually to a string before and call .toUpperCase() on it afterwards. One way would be:

const checkDeliveryTypeStr = `${this.checkDeliveryType}`;
const keyToDisplayMessage = `${checkDeliveryTypeStr.toUpperCase()}_${this.selectedAddressType.toUpperCase()}`;

But in general it would be a better idea to fix the type correctly in your entire flow.

Leave a comment