-
Notifications
You must be signed in to change notification settings - Fork 23
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
chai require from .http not supported #268
Comments
@zawiasam The problem is that chai switched to ESM with v5 (see Release Notes). This is not supported by the require. You would have to use |
@AnWeber Maybe I could help somehow, any hint where I could to start? |
@zawiasam With pleasure. It is actually also encapsulated and can therefore be worked on without the big picture. But the problem is complicated enough. |
@zawiasam Did you figure out how to do this? @AnWeber What would you recommend to use for testing complex assertions (e.g. check if an object list returned with response contains elements with specific properties, such as |
@AnWeber I manually installed Restarted VSCode, but I'm still getting an error that the module is missing: Did I miss a step? |
@alekdavisintel You are now right that Chai should be bundled. My idea of the tool initially came from a different direction. Just a small Postman replacement. The ideas I got from issues, have changed it. Using chai@v4 is supported. Only v5 is broken because of esm. NodeJS v22 brings better support to also require esm modules. Maybe this Problem is solved. I will retry a solution next week. But I try to survive the heat in italy at the moment
Probably Not. That is the way I used it |
@AnWeber I just installed the latest version of NodeJS 22.x, but I'm still getting errors trying to include So, looks like Node v22 does not fix this. |
You need to enable Support for ESM require, or you could Install v23 where this Support is active by default |
Sweet. Thank you so much. If anyone is interested. What you need to do is:
@host=https://httpbin.org
@value=abc
### Demo CHAI expect
GET /anything?value={{value}}
{{
const { expect } = require('chai');
test('EXPECT status code 200', () => {
expect(response.statusCode).to.equal(200);
});
}}
### Demo CHAI assert
GET /anything?value={{value}}
{{
const { assert } = require('chai');
test('ASSERT status code 200', () => {
assert.equal(response.statusCode, 200);
});
}}
### Demo CHAI should
GET /anything?value={{value}}
{{
require('chai').should();
test('SHOULD status code 200', () => {
response.statusCode.should.be.equal(200);
});
}} I will do a bit more testing (I have several versions of Thanks again. This is awesome. P.S. I should have mentioned that examples above use {
"devDependencies": {
"chai": "^4.5.0"
}
} Use |
Okay, a couple of tips for the the novices (after a few tests I did):
Once you do this, the code above will work. As I said, I will add this info along with the I hope |
I added some samples to https://github.com/alekdavis/httpyac-extras/blob/main/Tests/Demos/demo-7-Asserts-Chai.http |
Can't import chai for assertions
after sending request
error from vc extension
from CLI
package.json
The text was updated successfully, but these errors were encountered: