From f094c618e862086668eeb6e07a6cc5c0e8370300 Mon Sep 17 00:00:00 2001 From: GP Date: Thu, 28 Jun 2018 13:20:40 +0530 Subject: [PATCH] Introduce URL as input for nock. --- types/nock/index.d.ts | 7 +++++-- types/nock/nock-tests.ts | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/types/nock/index.d.ts b/types/nock/index.d.ts index 90eae08189..afebacf1e5 100644 --- a/types/nock/index.d.ts +++ b/types/nock/index.d.ts @@ -1,17 +1,20 @@ -// Type definitions for nock v9.1.3 +// Type definitions for nock v9.3.3 // Project: https://github.com/node-nock/nock // Definitions by: bonnici // Horiuchi_H // afharo // Matt R. Wilson // Garanzha Dmitriy +// GP // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// +import { Url } from 'url'; + export = nock; -declare function nock(basePath: string | RegExp, options?: nock.Options): nock.Scope; +declare function nock(basePath: string | RegExp | Url, options?: nock.Options): nock.Scope; declare namespace nock { export function cleanAll(): void; diff --git a/types/nock/nock-tests.ts b/types/nock/nock-tests.ts index 7ed4ecc25d..06f8458bcb 100644 --- a/types/nock/nock-tests.ts +++ b/types/nock/nock-tests.ts @@ -1,5 +1,6 @@ import nock = require('nock'); import * as fs from 'fs'; +import { URL } from 'url'; var scope: nock.Scope; var inst: nock.Interceptor; @@ -144,6 +145,11 @@ var couchdb = nock('http://myapp.iriscouch.com') email: 'pedro.teixeira@gmail.com' }); +// Using URL as input +var scope = nock(new URL('https://example.org/')) + .get('/resource') + .reply(200, 'url matched'); + // Specifying hostname var scope = nock('http://www.example.com') .get('/resource')