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

335
Vistas
mocha : testing a signup process with email-verification framework

I try to test my signup router post function which use email-verification framework,but mocha shows me the error message below : TypeError: Cannot read property 'findOne' of null

This my code :

function that invoke the error:

nev.resendVerificationEmail(email,(err,userExist) =>{
if(err){
      return res.status(404).send('Error : resending verification email failed');}
if(userExist){
      res.json({message : 'An email has been sent to you , again. Please check it to verify your account'});
}else{
      res.json({message : 'Your verification code has expired . Please sign up again'});

and this is the implementation of resendVerificationEmail function

var resendVerificationEmail = function(email, callback) {
var query = {};
query[options.emailFieldName] = email;

options.tempUserModel.findOne(query, function(err, tempUser) { //this the error handler I guess
  if (err) {
    return callback(err, null);
  }

  // user found (i.e. user re-requested verification email before expiration)
  if (tempUser) {
    // generate new user token
    tempUser[options.URLFieldName] = randtoken.generate(options.URLLength);
    tempUser.save(function(err) {
      if (err) {
        return callback(err, null);
      }

      sendVerificationEmail(getNestedValue(tempUser, options.emailFieldName), tempUser[options.URLFieldName], function(err) {
        if (err) {
          return callback(err, null);
        }
        return callback(null, true);
      });
    });

  } else {
    return callback(null, false);
  }
});

};

and this is my spec

describe(' SignUp : /POST Test with fake client request : ', () => {
    let req, res, statusCode, sendData,user;
    beforeEach((done) => {
        SignupModal.remove({}, (err) => {
            done();
        });

        user = {
            firstName : 'ben',
            secondName : 'wissem',
            username : 'wiss',
            email : 'xy@zt.sq',
            password : 'wissem'
        };
        res = {
            json: function (code, data) {
                statusCode = code;
                sendData = data;
            }
        };
    });

    it('should send 200 code', () => {
        chai.request(server)
            .post('/user/signup')
            .send(user)
            .end((err, res) => {
                res.statusCode.should.equal(200);
            });
    });

Can any one help me please ?!

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

if you want to end-to-end test email verification try EmailE2E.com, it's a free API that let's you send and receive emails from randomly generated inboxes. It's perfect for Firebase, Amazon Cognito, or other OAuth providers that use email verification codes during sign up. It also has a Javascript client you can use with Mocha.

over 4 years ago · Santiago Trujillo 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