I am currently using npm chai version 5.1.1 which now only supports import and not require. I have used dynamic imports which are working fine. However, when I am using the chai-http middleware with chai, it is not working as expected and is giving me an error.
Here is the syntax I am using:
let chai, expect, chaiHttp, request;
(async() => {
expect = (await import ('chai')).expect;
chai = (await import('chai')).default;
chaiHttp = (await import('chai-http')).default;
chai.use(chaiHttp);
})();
it("should return a 200 response", async function() {
const response = await chai.request(app).get('/abc');
expect(response).to.have.status(200);
});
It appears that chai.use(chaiHttp); is not functioning as expected due to the asynchronous behaviour of JavaScript. I am not sure why this is happening.
Can anyone help me understand this issue and suggest a possible fix?
pravin pawar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.