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

868
Visualizações
Node Express Mocha test: TypeError: chai.request is not a function

I have a Typscript app and API. I wrote the below test per numerous Google searches and some examples found here on SO and other places. I see no issue in the test code. Googling TypeError: chai.request is not a function, so far is getting me now where. Do you see my error below?

Thank you, thank you, thank you for any help :-)

enter image description here

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

I solved this by the following approach (Express.js with TypeScript)

import chai from 'chai';
import chaiHttp from 'chai-http';

chai.use(chaiHttp);

Hope it helps.

Remember to install @types/chai and other type definition packages for the block above to work

over 4 years ago · Santiago Trujillo Relatório

0

I can reproduce the problem if I enable the esModuleInterop compiler option. When this option is enabled, import * as chai from 'chai'; only imports the members that the chai module has at the time it is imported. Indeed, I believe it's considered dodgy to add exports to an ES module at runtime. Try import chai from 'chai'; or import chai = require('chai'); instead; either one is working for me.

over 4 years ago · Santiago Trujillo Relatório

0

You are mixing import and require syntax, it's a bad idea!

Use only import syntax :

import * as chai from 'chai';
import * as chai-http from 'chai-http';

chai.use(chai-http);

Edit

Unfortunately, it seems that the es6 module syntax is not supported in chai-http. You can see the issue here

import * as chai from 'chai';
import chaiHttp = require('chai-http');

chai.use(chai-http);
over 4 years ago · Santiago Trujillo 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