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 {
  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;
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest