OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Issue with chai-http middleware when using dynamic imports in chai version 5.1.1

  • Thread starter Thread starter pravin pawar
  • Start date Start date
P

pravin pawar

Guest
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:

Code:
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?

<p>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.</p>
<p>Here is the syntax I am using:</p>
<pre><code>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);
});
</code></pre>
<p>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.</p>
<p>Can anyone help me understand this issue and suggest a possible fix?</p>
 

Latest posts

J
Replies
0
Views
1
jbowerbir
J
Top