Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 845
Locohost Avatar asked Sep 02 '18 23:09

Locohost


1 Answers

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

like image 183
Toufiq Avatar answered Nov 15 '22 22:11

Toufiq