mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-07 00:07:07 +00:00
Adhere closer to chai-http's true implementation that extends the superagent Request instead of adding custom types. Necessary for being able to use the ca, key, cert and pfx methods with typings intact.
This commit is contained in:
@@ -37,6 +37,25 @@ chai.request(app)
|
||||
.get('/protected')
|
||||
.auth('user', 'pass');
|
||||
|
||||
// HTTPS request, from: https://github.com/visionmedia/superagent/commit/6158efbf42cb93d77c1a70887284be783dd7dabe
|
||||
const ca = fs.readFileSync('ca.cert.pem');
|
||||
const key = fs.readFileSync('key.pem');
|
||||
const cert = fs.readFileSync('cert.pem');
|
||||
const callback = (err: any, res: ChaiHttp.Response) => {};
|
||||
|
||||
chai.request(app)
|
||||
.post('/secure')
|
||||
.ca(ca)
|
||||
.key(key)
|
||||
.cert(cert)
|
||||
.end(callback);
|
||||
|
||||
const pfx = fs.readFileSync('cert.pfx');
|
||||
chai.request(app)
|
||||
.post('/secure')
|
||||
.pfx(pfx)
|
||||
.end(callback);
|
||||
|
||||
chai.request(app)
|
||||
.get('/search')
|
||||
.query({ name: 'foo', limit: 10 });
|
||||
|
||||
Vendored
+10
-25
@@ -9,6 +9,8 @@
|
||||
/// <reference types="node" />
|
||||
/// <reference types="chai" />
|
||||
|
||||
import request = require('superagent');
|
||||
|
||||
declare global {
|
||||
namespace Chai {
|
||||
interface ChaiStatic {
|
||||
@@ -53,31 +55,14 @@ declare global {
|
||||
on(event: string, fn: (...args: any[]) => void): void;
|
||||
}
|
||||
|
||||
interface Request extends FinishedRequest {
|
||||
attach(field: string, file: string|Buffer, filename: string): Request;
|
||||
set(field: string, val: string): Request;
|
||||
query(params: any): Request;
|
||||
send(data: any): Request;
|
||||
auth(user: string, name: string): Request;
|
||||
field(name: string, val: string): Request;
|
||||
buffer(): Request;
|
||||
parse(fn: (res: Response, cb: (e?: Error, r?: any) => void) => void): Request;
|
||||
end(callback?: (err: any, res: Response) => void): FinishedRequest;
|
||||
}
|
||||
|
||||
interface FinishedRequest<T = Response> {
|
||||
then<TR1 = T, TR2 = void>(success?: (res: T) => TR1 | PromiseLike<TR1>, failure?: (err: any) => TR2 | PromiseLike<TR2>): FinishedRequest<TR1>;
|
||||
catch(failure?: (err: any) => void): FinishedRequest<T>;
|
||||
}
|
||||
|
||||
interface Agent {
|
||||
get(url: string, callback?: (err: any, res: Response) => void): Request;
|
||||
post(url: string, callback?: (err: any, res: Response) => void): Request;
|
||||
put(url: string, callback?: (err: any, res: Response) => void): Request;
|
||||
head(url: string, callback?: (err: any, res: Response) => void): Request;
|
||||
del(url: string, callback?: (err: any, res: Response) => void): Request;
|
||||
options(url: string, callback?: (err: any, res: Response) => void): Request;
|
||||
patch(url: string, callback?: (err: any, res: Response) => void): Request;
|
||||
interface Agent {
|
||||
get(url: string, callback?: (err: any, res: Response) => void): request.Request;
|
||||
post(url: string, callback?: (err: any, res: Response) => void): request.Request;
|
||||
put(url: string, callback?: (err: any, res: Response) => void): request.Request;
|
||||
head(url: string, callback?: (err: any, res: Response) => void): request.Request;
|
||||
del(url: string, callback?: (err: any, res: Response) => void): request.Request;
|
||||
options(url: string, callback?: (err: any, res: Response) => void): request.Request;
|
||||
patch(url: string, callback?: (err: any, res: Response) => void): request.Request;
|
||||
}
|
||||
|
||||
interface TypeComparison {
|
||||
|
||||
Reference in New Issue
Block a user