Questions tagged [chai-http]
102 questions
0
votes
0 answers
Chai: TypeError: Cannot read property 'address' of undefined
I'm getting started with chai-HTTP testing and I don't really know why I keep getting
TypeError: Cannot read property 'address' of undefined
Does anyone know what is wrong with the code? I have tried some solutions I have found around here but none…
0
votes
0 answers
Cannot upload a CSV file to koa2 API server with chai-http through koa-multer
thanks for your time in advance. As the topic mentioned, I am trying to test my API server with Mocha and Chai-Http, the server used koa2 and Koa-multer to get uploaded files. However, when I trying to test it with the code below, I always get a…
![](../../users/profiles/13234936.webp)
Even_zhi
- 1
0
votes
0 answers
Why am I getting a Bad Request error on this POST request in Chai HTTP?
I'm trying to test a POST endpoint in Chai HTTP that sends the request, with a request body containing a JSON object, to a server built with Restify. For some reason I keep getting a Bad Request Error. When I debug the test I can see the request…
![](../../users/profiles/10463316.webp)
Greg
- 1
0
votes
0 answers
Async done() is not working in moch-chai.Unable to access http response
I am trying to follow what is provided here - https://www.chaijs.com/plugins/chai-http/
it('fails, as expected', function(done) { // <= Pass in done callback
chai.request('http://localhost:8080')
.get('/')
.end(function(err, res) {
…
![](../../users/profiles/14406629.webp)
KD_codes
- 1
0
votes
1 answer
chai-http: Cannot read property 'headers' of undefined at Assertion.
I get this error when I'm running my unit tests on gitlab pipeline, but it work fine on my local environement:
TypeError: Cannot read property 'headers' of undefined
at Assertion. (node_modules/chai-http/lib/http.js:175:19)
at…
![](../../users/profiles/11907450.webp)
Corentin
- 21
- 6
0
votes
1 answer
What is the proper way to test routes secured with jwt token?
While the following test passes I feel I'm doing this wrong. Am I expected to log in every time i need to test a secure route? I've tried passing global vars around after i get the initial token but passing vars i'm finding extremely counter…
![](../../users/profiles/290781.webp)
Parker
- 144
- 1
- 10
0
votes
0 answers
How can I call an API twice with chai.request() in node js to check a property 's uniqueness?
I have an API called createForm with the url below:
POST http://localhost:8000/api/forms/
I'm using chai and mocha for testing my APIs.
Here's how I test single call on this API and it succeeds:
it('it should create a form in db', (done) => {
…
![](../../users/profiles/9860413.webp)
ArminMz
- 77
- 1
- 8
0
votes
1 answer
Test try-catch on Express API with mocha, chai, chai-http and sinon
I have an API app created with Express with this function on a controller
/** UserController.ts */
--------------------------
public static get = async (req: Request, res: Response): Promise => {
try {
const user = await…
![](../../users/profiles/5798883.webp)
sergiodiego
- 1
- 2
0
votes
1 answer
chai.use(chaiHttp); Once or in every test file?
Adding Chai HTTP (https://www.chaijs.com/plugins/chai-http/) to a Node project tests.
Using the plugin (as in the documentation) is using:
var chai = require('chai')
, chaiHttp = require('chai-http');
chai.use(chaiHttp);
I'm wonder if I need to…
![](../../users/profiles/3879958.webp)
ET-CS
- 4,441
- 5
- 32
- 54
0
votes
1 answer
Test try catch with Mocha and Chai in Node + Express appp
I have nodeJS app with simple route as below:
const express = require('express')
const router = express.Router();
const logger = require('../logger');
router.use('/logMessage',(req, res) => {
try {
logger.info(req.query.message);
…
![](../../users/profiles/5340535.webp)
Don
- 1,312
- 1
- 8
- 16
0
votes
0 answers
Unit Testing HTTP Post request with database access
Hi I'm currently trying to learn and implement some unit testing for my HTTP Requests. currently I have a SQlite db setup, and a simple post request. This is the test I have written so far:
"use strict";
process.env.NODE_ENV = 'test';
const chai =…
![](../../users/profiles/10017632.webp)
Taylor Southorn
- 11
- 3
0
votes
2 answers
Chai.request is not a function
I have the following simple code
import app from '../src/app';
import * as chai from 'chai';
import chaiHttp = require('chai-http');
chai.use(chaiHttp);
const expect = chai.expect;
describe('Get /', () => {
it('Should say hi there', async ()…
![](../../users/profiles/4873380.webp)
Asool
- 7,423
- 4
- 25
- 41
0
votes
0 answers
chai-http response is always undefined
i'm try to run this test but the res is always undifined , its weird because when i try it from postman its work fine
my test:
const { chai, assert, should, expect, sinon } = require("../baseTest");
describe.only("Test the Default routes",…
![](../../users/profiles/12268903.webp)
דודו שטראוס
- 63
- 1
- 6
0
votes
1 answer
testing with chai-http test didn't run
i try to test my routes file with chai-http but it filed because:"TypeError: Suite argument "title" must be a string. Received type "number"
my test.js
const { assert, should, expect, sinon } = require("../baseTest");
const chai =…
![](../../users/profiles/12268903.webp)
דודו שטראוס
- 63
- 1
- 6
0
votes
0 answers
chai-http not always seeing ETag header, possibly due to CORS?
I'm written a suite of tests using mocha (6.2.2), chai (4.2.0) and chai-http (4.3.0) to test a micro-service we've written. Sometimes, the ETag header we add ourselves (first removing the 'Express' one using an on-headers listener) doesn't appear in…
![](../../users/profiles/12438642.webp)
Michael Beale
- 31
- 1