Merge pull request #12725 from pimterry/nock-optionally-t2

Add optionally() to Nock
This commit is contained in:
Horiuchi_H
2016-11-17 12:35:39 +09:00
committed by GitHub
2 changed files with 7 additions and 1 deletions

3
nock/index.d.ts vendored
View File

@@ -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 <https://github.com/bonnici>, Horiuchi_H <https://github.com/horiuchi>
// 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;

View File

@@ -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('/')