Merge pull request #3411 from optical/nock-enhancements

Add additional methods to nock.
This commit is contained in:
Masahiro Wakame
2015-01-08 23:37:44 +09:00
2 changed files with 84 additions and 2 deletions

View File

@@ -4,29 +4,54 @@ 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.patch(str, regex);
inst = inst.post(str);
inst = inst.post(str, data);
inst = inst.post(str, obj);
inst = inst.post(str, regex);
inst = inst.put(str);
inst = inst.put(str, data);
inst = inst.put(str, obj);
inst = inst.put(str, regex);
inst = inst.delete(str);
inst = inst.delete(str, data);
inst = inst.delete(str, obj);
inst = inst.delete(str, regex);
inst = inst.merge(str);
inst = inst.merge(str, data);
inst = inst.merge(str, obj);
inst = inst.merge(str, regex);
inst = inst.intercept(str, str);
inst = inst.intercept(str, str, str);
inst = inst.intercept(str, str, obj);
inst = inst.intercept(str, str, regex);
inst = inst.intercept(str, str, str, value);
inst = inst.intercept(str, str, obj, value);
inst = inst.intercept(str, str, regex, value);
inst = inst.reply(num);
inst = inst.reply(num, str);
@@ -41,9 +66,17 @@ inst = inst.reply(num, (uri: string, body: string) => {
}, headers);
inst = inst.replyWithFile(num, str);
inst = inst.times(4);
inst = inst.once();
inst = inst.twice();
inst = inst.thrice();
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 +94,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();

41
nock/nock.d.ts vendored
View File

@@ -1,4 +1,4 @@
// Type definitions for nock
// Type definitions for nock v0.54.0
// Project: https://github.com/pgte/nock
// Definitions by: bonnici <https://github.com/bonnici>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
@@ -22,11 +22,32 @@ declare module "nock" {
export interface Scope {
get(path: string, data?: string): Scope;
post(path: string, data?: string): Scope;
post(path: string, data?: Object): Scope;
post(path: string, regex?: RegExp): Scope;
patch(path: string, data?: string): Scope;
patch(path: string, data?: Object): Scope;
patch(path: string, regex?: RegExp): Scope;
put(path: string, data?: string): Scope;
put(path: string, data?: Object): Scope;
put(path: string, regex?: RegExp): Scope;
head(path: string): Scope;
delete(path: string, data?: string): Scope;
delete(path: string, data?: Object): Scope;
delete(path: string, regex?: RegExp): Scope;
merge(path: string, data?: string): Scope;
merge(path: string, data?: Object): Scope;
merge(path: string, regex?: RegExp): Scope;
intercept(path: string, verb: string, body?: string, options?: any): Scope;
intercept(path: string, verb: string, body?: Object, options?: any): Scope;
intercept(path: string, verb: string, body?: RegExp, options?: any): Scope;
reply(responseCode: number, body?: string, headers?: Object): Scope;
reply(responseCode: number, body?: Object, headers?: Object): Scope;
@@ -44,18 +65,34 @@ declare module "nock" {
persist(): Scope;
log(out: () => void): Scope;
delay(timeMs: number): Scope;
delayConnection(timeMs: number): Scope;
times(repeats: number): Scope;
once(): Scope;
twice(): Scope;
thrice(): 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;
}
}
}