Retyped Chai-HTTP Typings

0.0.0-0 · abandoned · verified Wed Apr 22

This package provides TypeScript ambient type declarations for the `chai-http` library. It originates from the `retyped` project, which aimed to offer curated typings for various JavaScript libraries. However, the `retyped` project itself appears to be abandoned, with most packages, including this one, maintaining a `0.0.0-0` version number, indicating no active development or updates. Modern `chai-http` (version 4.2.4 and above) ships with its own built-in TypeScript definitions, making external typing packages like `retyped-chai-http-tsd-ambient` largely obsolete. Users are generally advised to rely on `chai-http`'s native types rather than this unmaintained package or even the stub `@types/chai-http` package.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a basic TypeScript test setup using `chai`, `chai-http`, and `mocha` to make and assert HTTP requests against a simple Express.js application, leveraging the provided typings.

import * as chai from 'chai';
import chaiHttp from 'chai-http';
import { Application } from 'express'; // Assuming Express.js application
import 'mocha'; // For test runner globals

// Optionally import superagent types if not implicitly resolved by chai-http's built-in types
// import '@types/superagent';

// Initialize Chai HTTP plugin
chai.use(chaiHttp);

// Create a dummy Express app for testing
const app: Application = require('express')();
app.get('/test', (req, res) => res.status(200).send('Hello Test!'));
app.post('/data', (req, res) => res.status(201).json({ message: 'Data received' }));

describe('Chai-HTTP with TypeScript', () => {
  it('should get a successful response from /test', (done) => {
    chai.request(app)
      .get('/test')
      .end((err, res) => {
        chai.expect(err).to.be.null;
        chai.expect(res).to.have.status(200);
        chai.expect(res.text).to.equal('Hello Test!');
        done();
      });
  });

  it('should post data and get a created response from /data', (done) => {
    chai.request(app)
      .post('/data')
      .send({ item: 'test' })
      .end((err, res) => {
        chai.expect(err).to.be.null;
        chai.expect(res).to.have.status(201);
        chai.expect(res).to.be.json;
        chai.expect(res.body.message).to.equal('Data received');
        done();
      });
  });
});

view raw JSON →