Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

143
Vistas
Jest not finding my function and complains of a TypeError

I created a Node.js application which exports a validate function. When I use the validator in a Jest test. Jest complains the validate is not a function. the function is clearly exported and when I click on it in VS Code, it goes right to the function. Here is the validate function exported in a file called validator.js:

          // validator.js
             module.exports = {  
               validate: (req) => { 
               let policyType = req.body.policy_type;
               let length = req.body.term_length;
               
               if (!policyType) {
                return false;
               }
                if (!length) {
                 return false;
                }
                return  true;
               }
              };

I then pull in the function in the Jest test as follows:

        const validate = require("./validator.js");
        describe(“Validator Test", ()=> {
        test('Ensure expected return ', ()=>{
        const req = {};
        req.body.policy_type= '';
        req.body.term_length= '';
    
        //TypeError: validate is not a function
         expect(validate(req)).toEqual(expectedOut);
        
       })

Jest complains that validate is not a function. I simply don't know why it is complaining about not finding the function which can be found in other functions in the node application. I searched online but could not find a use case like mine. As I am quite new to Jest, I would appreciate any help in resolving this. Thank you.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The module.exports works fine. The problem was related to another import which wasn't resolved in the validator.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda