From 9ff4ff6377ed8c962b5200facf7a494ed38e7078 Mon Sep 17 00:00:00 2001 From: Jared Date: Mon, 5 Jan 2015 19:41:01 +1300 Subject: [PATCH] Add additional methods to nock. --- nock/nock-tests.ts | 33 +++++++++++++++++++++++++++++++++ nock/nock.d.ts | 28 +++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/nock/nock-tests.ts b/nock/nock-tests.ts index f3c166aa1..b64163007 100644 --- a/nock/nock-tests.ts +++ b/nock/nock-tests.ts @@ -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(); \ No newline at end of file diff --git a/nock/nock.d.ts b/nock/nock.d.ts index 18119e1db..6cafb54c6 100644 --- a/nock/nock.d.ts +++ b/nock/nock.d.ts @@ -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; + } } }