🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

chai-http

Package Overview
Dependencies
Maintainers
0
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chai-http - npm Package Compare versions

Comparing version

to
5.1.0

2

index.js
import fn from './lib/http.js';
export default fn;
export * as request from './lib/request.js';

2

lib/http.js

@@ -384,3 +384,3 @@ /*!

Assertion.addMethod('param', function (name, value) {
Assertion.addMethod('param', function () {
const assertion = new Assertion();

@@ -387,0 +387,0 @@ _.transferFlags(this, assertion);

{
"name": "chai-http",
"version": "5.0.0",
"version": "5.1.0",
"description": "Extend Chai Assertion library with tests for http apis",

@@ -27,3 +27,9 @@ "author": "Jake Luer <jake@alogicalparadox.com>",

],
"main": "./index",
"main": "./index.js",
"exports": {
".": {
"import": "./index.js",
"types": "./types/index.d.ts"
}
},
"types": "./types/index.d.ts",

@@ -59,3 +65,3 @@ "repository": {

"@eslint/js": "^9.3.0",
"@types/chai": "^4.3.15",
"@types/chai": "^4.3.16",
"@types/superagent": "^8.1.7",

@@ -62,0 +68,0 @@ "chai": "^5.1.0",

@@ -23,6 +23,15 @@ # Chai HTTP [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) [![NPM version](https://img.shields.io/npm/v/chai-http.svg)](https://img.shields.io/npm/v/chai-http.svg)

```js
import chaiModule from "chai";
import * as chai from "chai";
import chaiHttp from "chai-http";
const chai = chaiModule.use(chaiHttp);
chai.use(chaiHttp);
// if you need to access `request`
import {default as chaiHttp, request} from "chai-http";
chai.use(chaiHttp);
request.get(...).send(...);
// or setting up an app
request.execute(app);
```

@@ -53,3 +62,5 @@

```js
chai.request.execute(app)
import {request} from 'chai-http';
request.execute(app)
.get('/')

@@ -65,4 +76,6 @@ ```

```js
const requester = chai.request.Request(app).keepOpen()
import {request} from 'chai-http';
const requester = request.Request(app).keepOpen()
Promise.all([

@@ -82,3 +95,5 @@ requester.get('/a'),

```js
chai.request.execute('http://localhost:8080')
import {request} from 'chai-http';
request.execute('http://localhost:8080')
.get('/')

@@ -96,3 +111,3 @@ ```

| `.type(dataType)` | Change the type of the data sent from the `.send()` method (xml, form, etc) |
| `.attach(field, file, attachment)` | Attach a file |
| `.attach(field, file, attachment)` | Attach a file |
| `.auth(username, password)` | Add auth headers for Basic Authentication |

@@ -105,4 +120,6 @@ | `.query(parmasObject)` | Chain on some GET parameters |

```js
import {request} from 'chai-http';
// Set a request header
chai.request.execute(app)
request.execute(app)
.put('/user/me')

@@ -115,4 +132,6 @@ .set('Content-Type', 'application/json')

```js
import {request} from 'chai-http';
// Send some JSON
chai.request.execute(app)
request.execute(app)
.put('/user/me')

@@ -124,4 +143,6 @@ .send({ password: '123', confirmPassword: '123' })

```js
import {request} from 'chai-http';
// Send some Form Data
chai.request.execute(app)
request.execute(app)
.post('/user/me')

@@ -138,4 +159,6 @@ .type('form')

```js
import {request} from 'chai-http';
// Attach a file
chai.request.execute(app)
request.execute(app)
.post('/user/avatar')

@@ -147,12 +170,14 @@ .attach('imageField', fs.readFileSync('avatar.png'), 'avatar.png')

```js
import {request} from 'chai-http';
// Authenticate with Basic authentication
chai.request.execute(app)
request.execute(app)
.get('/protected')
.auth('user', 'pass')
// Authenticate with Bearer Token
chai.request.execute(app)
request.execute(app)
.get('/protected')
.auth(accessToken, { type: 'bearer' })
.auth(accessToken, { type: 'bearer' })
```

@@ -162,4 +187,6 @@

```js
import {request} from 'chai-http';
// Chain some GET query parameters
chai.request.execute(app)
request.execute(app)
.get('/search')

@@ -180,3 +207,5 @@ .query({name: 'foo', limit: 10}) // /search?name=foo&limit=10

```js
chai.request.execute(app)
import {request} from 'chai-http';
request.execute(app)
.put('/user/me')

@@ -203,4 +232,6 @@ .send({ password: '123', confirmPassword: '123' })

```js
import {request} from 'chai-http';
it('fails, as expected', function(done) { // <= Pass in done callback
chai.request.execute('http://localhost:8080')
request.execute('http://localhost:8080')
.get('/')

@@ -214,3 +245,3 @@ .end((err, res) => {

it('succeeds silently!', () => { // <= No done callback
chai.request.execute('http://localhost:8080')
request.execute('http://localhost:8080')
.get('/')

@@ -233,3 +264,5 @@ .end((err, res) => {

```js
chai.request.execute(app)
import {request} from 'chai-http';
request.execute(app)
.put('/user/me')

@@ -251,4 +284,6 @@ .send({ password: '123', confirmPassword: '123' })

```js
import {request} from 'chai-http';
// Log in
const agent = chai.request.agent(app)
const agent = request.agent(app)
agent

@@ -268,3 +303,3 @@ .post('/session')

Note: The server started by `chai.request.agent(app)` will not automatically close following the test(s). You should call `agent.close()` after your tests to ensure your program exits.
Note: The server started by `request.agent(app)` will not automatically close following the test(s). You should call `agent.close()` after your tests to ensure your program exits.

@@ -271,0 +306,0 @@ ## Assertions

@@ -8,3 +8,3 @@ // Definitions by: Wim Looman <https://github.com/Nemo157>

/// <reference types="chai" />
import * as request from 'superagent';
import * as superAgentRequest from 'superagent';

@@ -52,4 +52,4 @@ // Merge namespace with global chai

namespace ChaiHttp {
interface Response extends request.Response {}
interface Agent extends request.SuperAgentStatic {
interface Response extends superAgentRequest.Response {}
interface Agent extends superAgentRequest.SuperAgentStatic {
keepOpen(): Agent;

@@ -64,1 +64,5 @@ close(callback?: (err: any) => void): Agent;

export default chaiHttp;
declare const request: Chai.ChaiHttpRequest;
export {request};