Add additional methods to nock.

This commit is contained in:
Jared
2015-01-05 19:41:01 +13:00
parent 494b30d232
commit 9ff4ff6377
2 changed files with 60 additions and 1 deletions

View File

@@ -4,29 +4,47 @@ import nock = require('nock');
var inst: nock.Scope;
var str: string;
var strings: string[];
var bool: boolean;
var data: string;
var num: number;
var obj: {};
var objects: Object[];
var value: any;
var regex: RegExp;
var options: nock.Options;
var headers: Object;
inst = inst.head(str);
inst = inst.get(str);
inst = inst.get(str, data);
inst = inst.patch(str);
inst = inst.patch(str, str);
inst = inst.patch(str, obj);
inst = inst.post(str);
inst = inst.post(str, data);
inst = inst.post(str, obj);
inst = inst.put(str);
inst = inst.put(str, data);
inst = inst.put(str, obj);
inst = inst.delete(str);
inst = inst.delete(str, data);
inst = inst.delete(str, obj);
inst = inst.merge(str);
inst = inst.merge(str, data);
inst = inst.merge(str, obj);
inst = inst.intercept(str, str);
inst = inst.intercept(str, str, str);
inst = inst.intercept(str, str, obj);
inst = inst.intercept(str, str, str, value);
inst = inst.intercept(str, str, obj, str);
inst = inst.reply(num);
inst = inst.reply(num, str);
@@ -44,6 +62,9 @@ inst = inst.replyWithFile(num, str);
inst = inst.defaultReplyHeaders(value);
inst = inst.matchHeader(str, str);
inst = inst.delay(num);
inst = inst.delayConnection(num);
inst = inst.filteringPath(regex, str);
inst = inst.filteringPath((path: string) => {
return str;
@@ -61,3 +82,15 @@ inst = inst.log(() => {
inst.done();
bool = inst.isDone();
inst.restore();
objects = inst.pendingMocks();
nock.recorder.rec();
nock.recorder.rec(true);
nock.recorder.rec({
dont_print: true,
output_objects: true
});
strings = nock.recorder.play();
objects = nock.recorder.play();

28
nock/nock.d.ts vendored
View File

@@ -22,11 +22,26 @@ declare module "nock" {
export interface Scope {
get(path: string, data?: string): Scope;
post(path: string, data?: string): Scope;
post(path: string, data?: Object): Scope;
patch(path: string, data?: string): Scope;
patch(path: string, data?: Object): Scope;
put(path: string, data?: string): Scope;
put(path: string, data?: Object): Scope;
head(path: string): Scope;
delete(path: string, data?: string): Scope;
delete(path: string, data?: Object): Scope;
merge(path: string, data?: string): Scope;
merge(path: string, data?: Object): Scope;
intercept(path: string, verb: string, body?: string, options?: any): Scope;
intercept(path: string, verb: string, body?: Object, options?: any): Scope;
reply(responseCode: number, body?: string, headers?: Object): Scope;
reply(responseCode: number, body?: Object, headers?: Object): Scope;
@@ -44,18 +59,29 @@ declare module "nock" {
persist(): Scope;
log(out: () => void): Scope;
delay(timeMs: number): Scope;
delayConnection(timeMs: number): Scope;
done(): void;
isDone(): boolean;
restore(): void;
pendingMocks(): Object[];
}
export interface Recorder {
rec(capture?: boolean): void;
play(): string[];
rec(options?: RecorderOptions): void;
play(): any[];
}
export interface Options {
allowUnmocked?: boolean;
}
export interface RecorderOptions {
dont_print?: boolean;
output_objects?: boolean;
enable_reqheaders_recording?: boolean;
}
}
}