UNPKG

2.21 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 type SuperAgentTest = SuperTest<Test> &
40 Pick<
41 Request,
42 | 'use'
43 | 'on'
44 | 'set'
45 | 'query'
46 | 'type'
47 | 'accept'
48 | 'auth'
49 | 'withCredentials'
50 | 'retry'
51 | 'ok'
52 | 'redirects'
53 | 'timeout'
54 | 'buffer'
55 | 'serialize'
56 | 'parse'
57 | 'ca'
58 | 'key'
59 | 'pfx'
60 | 'cert'
61 >;
62 interface SuperTest<T extends superagent.SuperAgentRequest> extends superagent.SuperAgent<T> {
63 host(host: string): T;
64 }
65}