Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda