Skip to content

Commit

Permalink
Merge pull request #12725 from pimterry/nock-optionally-t2
Browse files Browse the repository at this point in the history
Add optionally() to Nock
  • Loading branch information
horiuchi committed Nov 17, 2016
2 parents d0927ca + 5dbf2b7 commit ff368e4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion nock/index.d.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions nock/nock-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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('/')
Expand Down

0 comments on commit ff368e4

Please sign in to comment.