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

148
Vistas
Start mocha chai test when app is a Promise

A very simplification of the code where the server starts asynchronously

// server/app.js
let appPromise = new Promise((resolve, reject) => {
   [..async stuff..]
   const app = express()
   const server = http.createServer(app)
   server.listen(config.port, config.ip, () => {...}
})    
export default appPromise;

Where from I starts the tests:

// test/index.js
require('@babel/core').transform('code', {});
require('@babel/register');
let tests = require('./tests.js');

module.exports = {tests};

The code where tests are implemented:

// test/test.js
const app = require('../server/app')
const chai = require('chai')
const chaiHttp = require('chai-http')
chai.use(chaiHttp);
chai.should();
app.then(() => {
    describe(..tests...)
})

The error I get:

.then() is not a function

What's going wrong?

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

0

I believe your issue is that you are using ES6 export, but not importing in the ES6 way.

Your import of "app" should be:

import appPromise from '../server/app';

Also, your promise in "app.js" doesn't seem to resolve anything, if that isn't an omission, you need to resolve something in your promise for .then() to work. Here is a working example:

const appPromise = new Promise((resolve, reject) => {
    resolve('appPromise resolved');
});
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