-
-
Notifications
You must be signed in to change notification settings - Fork 698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@types/chai seems not to be adapted to version 5.0.0 #1578
Comments
This is because the project is esm only now. As the error message says, you would have to use a dynamic import to import it since you're in a commonjs project. Your package.json doesn't have I have an example here: if you're unable to make your project ESM-only, you will have to use a dynamic import ( We're still publishing 4.x versions for security etc. |
With mocha I did someting like so: const chaiHttp = require("chai-http");
let chai;
before(async () => {
await import("chai").then((result) => {
chai = result;
// Configure chai
chai.use(chaiHttp);
chai.should();
});
}); issue is that somehow chai.request is failing... TypeError: chai.request is not a function is chai-http 4.4.0 not compatible with chai 5.x? |
Okay it seems with the new version the use functionality is broken... |
for now (maybe permanently, depending on the outcome of 1569), you can do: await import("chai").then((result) =>
chai = result.use(chaiHttp);
}); |
You can try import just methods from 'chai' like this:
|
I can't take it anymore with Chai + Cha-http with ESM (even when not using TS, but just JS). It just impossible to import those two libs. I get |
You can try this way:
and then call:
|
Ow so |
yes, import {use} from 'chai';
import chaiHttp from 'chai-http';
const chai = use(chaiHttp); we have an issue open to investigate if there's any way we can improve this pattern |
Today I suffer again with the same problem but this time just using plain ES6 javascript (no typescript): Yes my code looks like this (I removed the should & expect imports for clarity): import { use } from 'chai'
import chaiHttp from 'chai-http'
import app from '../src/index.js'
const chai = use(chaiHttp)
// ... some it(... ) test.... And then:
chai.request(app) // <-- this line is failing still!!
.get("/example") Vscode is saying this is valid: OK, moving to |
This worked for me: process.env.NODE_ENV = "test";
import chaiHttp from "chai-http";
import app from "../main.js";
import * as chai from "chai";
const should = chai.should();
const expect = chai.expect;
const use = chai.use;
const request = use(chaiHttp).request.execute;
describe("/First Test Collection", () => {
it("test default API welcome route...", (done) => {
request(app)
.get("/") // Endpoint to test
.end((err, res) => {
res.should.have.status(200); // Check status code
res.body.should.be.a("object");
done(); // Signal async completion
});
});
it("expects two values to be equal....", () => {
// given
let expectedValue = 10; // when
let actualValue = 5;
expect(actualValue).not.to.equal(expectedValue); // then
});
}); |
As chai only supports esm, not commjs since v5, adjust the setup code to use dynamic imports. See chaijs/chai#1578 for more. Change-Id: I3c34043504bdf0c881eed4dabbe9e4fc8bb0b362
import chai from 'chai'
does not work with chai version 5.0.0.and executing
ts-mocha ./test.spec.ts"
Raises the following error
Other imports work fine.
tsconfig.json
:package.json
:The text was updated successfully, but these errors were encountered: