From 5dbf2b7a0c31e9faa563e99c79adb179c7990ffd Mon Sep 17 00:00:00 2001 From: Tim Perry Date: Wed, 16 Nov 2016 18:40:58 +0100 Subject: [PATCH] Add optionally() to nock --- nock/index.d.ts | 3 ++- nock/nock-tests.ts | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/nock/index.d.ts b/nock/index.d.ts index db852f596a..447c591803 100644 --- a/nock/index.d.ts +++ b/nock/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for nock v8.0.0 +// Type definitions for nock v8.2.0 // Project: https://github.com/node-nock/nock // Definitions by: bonnici , Horiuchi_H // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -91,6 +91,7 @@ declare namespace nock { once(): this; twice(): this; thrice(): this; + optionally(): this; delay(opts: number | { head?: number; body?: number; }): this; delayBody(timeMs: number): this; diff --git a/nock/nock-tests.ts b/nock/nock-tests.ts index d9a6844915..0d1b11159f 100644 --- a/nock/nock-tests.ts +++ b/nock/nock-tests.ts @@ -76,6 +76,8 @@ inst = inst.once(); inst = inst.twice(); inst = inst.thrice(); +inst = inst.optionally(); + scope = scope.defaultReplyHeaders(value); scope = scope.matchHeader(str, str); @@ -412,6 +414,9 @@ nock('http://zombo.com').get('/').once().reply(200, 'Ok'); nock('http://zombo.com').get('/').twice().reply(200, 'Ok'); nock('http://zombo.com').get('/').thrice().reply(200, 'Ok'); +// Make responding optional +nock('http://zombo.com').get('/').optionally().reply(200, 'Ok'); + // Delay the response body nock('http://my.server.com') .get('/')