-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from corinnaerin/typescript_def
Add typescript definition file
- Loading branch information
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { Request, Response } from 'express'; | ||
|
||
declare module 'node-mocks-http' { | ||
|
||
export type RequestMethod = | ||
'GET' | 'HEAD'| 'POST' | 'PUT' | 'DELETE' | 'TRACE' | 'CONNECT'; | ||
|
||
export interface Params { | ||
[key: string]: any; | ||
} | ||
|
||
export interface Session { | ||
[key: string]: string; | ||
} | ||
|
||
export interface Cookies { | ||
[key: string]: string; | ||
} | ||
|
||
export interface Headers { | ||
[key: string]: string; | ||
} | ||
|
||
export interface Query { | ||
[key: string]: string; | ||
} | ||
|
||
export interface Files { | ||
[key: string]: string; | ||
} | ||
|
||
export interface Body { | ||
[key: string]: string; | ||
} | ||
|
||
export interface RequestOptions { | ||
method?: RequestMethod; | ||
url?: string; | ||
originalUrl?: string; | ||
path?: string; | ||
params?: Params; | ||
session?: Session; | ||
cookies?: Cookies; | ||
signedCookies?: Cookies; | ||
headers?: Headers; | ||
body?: Body; | ||
query?: Query; | ||
files?: Files; | ||
} | ||
|
||
export interface MockRequest extends Request { | ||
_setParameter: (key: string, value: string) => void; | ||
_setSessionVariable: (variable: string, value: string) => void; | ||
_setCookiesVariable: (variable: string, value: string) => void; | ||
_setSignedCookiesVariable: (variable: string, value: string) => void; | ||
_setHeadersCookiesVariable: (variable: string, value: string) => void; | ||
_setFilesCookiesVariable: (variable: string, value: string) => void; | ||
_setMethod: (method: string) => void; | ||
_setURL: (value: string) => void; | ||
_setOriginalUrl: (value: string) => void; | ||
_setBody: (body: Body) => void; | ||
_addBody: (key: string, value: any) => void; | ||
} | ||
|
||
export interface ResponseOptions { | ||
eventEmitter?: any; | ||
writableStream?: any; | ||
req?: any; | ||
} | ||
|
||
export interface MockResponse extends Response { | ||
_isEndCalled: () => boolean; | ||
_getHeaders: () => Headers; | ||
_getData: () => any; | ||
_getStatusCode: () => number; | ||
_getStatusMessage: () => string; | ||
_isJSON: () => boolean; | ||
_isUTF8: () => boolean; | ||
_isDataLengthValid: () => boolean; | ||
_getRedirectUrl: () => string; | ||
_getRenderData: () => any; | ||
} | ||
|
||
export function createRequest(options?: RequestOptions): MockRequest; | ||
|
||
export function createResponse(options?: ResponseOptions): MockResponse; | ||
|
||
export interface Mocks { | ||
req: MockRequest; | ||
res: MockResponse; | ||
} | ||
|
||
export function createMocks(reqOptions?: RequestOptions, resOptions?: ResponseOptions): Mocks; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters