Getting a "Is Not a Function" Error While Running a Test (Javascript, Cypress)
Below Is My Code and When I Run My Test It Comes up as Months Is Not a Function. This Is for a Cypress Test. Any Idea Where I Am Going Wrong? Class Dateutils {...
below is my code and when I run my test it comes up as months is not a function. This is for a cypress test. Any idea where I am going wrong?
class DateUtils {
getMonthIndexFromName(monthName) {
months = {
January: '1',
Febuary: '2',
March: '3',
April: '4',
May: '5',
June: '6',
July: '7',
August: '8',
September: '9',
October: '10',
Novemebr: '11',
December: '12',
};
return months(monthName);
}
}
export default DateUtils;
1 Answer
months is an object, not a function. What you probably want is months[monthName] to dynamically select the property in monthName from the months object.