Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
Mocha Error: "isNumberPrime" function is not a function error

I created a function to check if a number is prime & export it to unit test it like so:

/**
 * Method checks if the number is prime & returns true or false
 * @param {number} num - number to be checked if it's prime
 * @returns {boolean} - true if num is prime, false if not
 */
 const isNumberPrime = (num) => num < 10 ? [2, 3, 5, 7].includes(num) : ![2, 3, 5, 7].some(i => !(num % i));

exports.modules = { isNumberPrime };

However, when I ran npm test, I get the error: TypeError: isNumberPrime is not a function. This is my mocha file:

const { expect } = require('chai');
const isNumberPrime = require('../utils/prime-number.js');

describe('Util methods', () => {
  it('should return true if number is prime', () => {
    const primeNumber = isNumberPrime(7);

    expect(primeNumber).to.be.true;
  });
});

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you need to either add {isPrimeNumber} in the import on mocha or set module.exports equal too your function

module.exports = isPrimeNumber;

or

const {isNumberPrime} = require('../utils/prime-number.js');
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!