Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Jest saying "Not a function" when it is defined as function

I am writing jest for this simple function:

function isVowel(ch) {
  ch = ch.toUpperCase();

  return ch == "A" || ch == "E" || ch == "I" || ch == "O" || ch == "U";
}

this is the jest:

const isVowel = require("./isVowel");
test("a is vowel", () => {
  const ch = isVowel("a");
  expect(ch).toBe("A");
});

on running, it gives error: TypeError: isVowel is not a function

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

how to resolve it?

>Solution :

I assume you write your code in commonjs format due to the way you require it in your test file so you just simply export like this:

// isVowel.js

function isVowel(ch) {
  ch = ch.toUpperCase();

  return ch == "A" || ch == "E" || ch == "I" || ch == "O" || ch == "U";
}

module.exports = isVowel;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading