UNPKG

2.32 kBTypeScriptView Raw
1// Type definitions for SuperTest v2.0.1
2// Project: https://github.com/visionmedia/supertest
3// Definitions by: Alex Varju <https://github.com/varju>
4// Petteri Parkkila <https://github.com/pietu>
5// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6// TypeScript Version: 3.0
7
8import * as superagent from 'superagent';
9
10export = supertest;
11
12declare function supertest(app: any): supertest.SuperTest<supertest.Test>;
13declare namespace supertest {
14 interface Response extends superagent.Response {}
15
16 interface Request extends superagent.SuperAgentRequest {}
17
18 type CallbackHandler = (err: any, res: Response) => void;
19 interface Test extends superagent.SuperAgentRequest {
20 app?: any;
21 url: string;
22 serverAddress(app: any, path: string): string;
23 expect(status: number, callback?: CallbackHandler): this;
24 expect(status: number, body: any, callback?: CallbackHandler): this;
25 expect(checker: (res: Response) => any, callback?: CallbackHandler): this;
26 expect(body: string, callback?: CallbackHandler): this;
27 expect(body: RegExp, callback?: CallbackHandler): this;
28 expect(body: Object, callback?: CallbackHandler): this;
29 expect(field: string, val: string, callback?: CallbackHandler): this;
30 expect(field: string, val: RegExp, callback?: CallbackHandler): this;
31 end(callback?: CallbackHandler): this;
32 }
33
34 interface AgentOptions {
35 ca?: any;
36 }
37 function agent(app?: any, options?: AgentOptions): SuperAgentTest;
38
39 interface SuperTest<T extends superagent.SuperAgentRequest> extends superagent.SuperAgent<T> {}
40 interface SuperTestWithHost<T extends superagent.SuperAgentRequest> extends SuperTest<T> {
41 host(host: string): this;
42 }
43 type SuperAgentTest = SuperTestWithHost<Test> &
44 Pick<
45 Request,
46 | 'use'
47 | 'on'
48 | 'set'
49 | 'query'
50 | 'type'
51 | 'accept'
52 | 'auth'
53 | 'withCredentials'
54 | 'retry'
55 | 'ok'
56 | 'redirects'
57 | 'timeout'
58 | 'buffer'
59 | 'serialize'
60 | 'parse'
61 | 'ca'
62 | 'key'
63 | 'pfx'
64 | 'cert'
65 >;
66}