mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-05 23:37:04 +00:00
[nock] Add matchHeader to Interceptor. (#35022)
This method is available on the Scope or Interceptor level, however, the type was only included on Scope before.
This commit is contained in:
committed by
Pranav Senthilnathan
parent
8024692790
commit
d0204038a4
Vendored
+4
-3
@@ -1,5 +1,5 @@
|
||||
// Type definitions for nock v9.3.3
|
||||
// Project: https://github.com/node-nock/nock
|
||||
// Type definitions for nock 10.0
|
||||
// Project: https://github.com/nock/nock
|
||||
// Definitions by: bonnici <https://github.com/bonnici>
|
||||
// Horiuchi_H <https://github.com/horiuchi>
|
||||
// afharo <https://github.com/afharo>
|
||||
@@ -86,7 +86,7 @@ declare namespace nock {
|
||||
}
|
||||
|
||||
export interface Interceptor {
|
||||
query(params: boolean | { (querObject: any): boolean; } | any): this;
|
||||
query(params: boolean | { (queryObject: any): boolean; } | any): this;
|
||||
|
||||
reply(responseCode: number, body?: string | any, headers?: HttpHeaders): Scope;
|
||||
reply(responseCode: number, callback: (uri: string, body: string, cb?: ReplyCallback) => ReplyCallbackResult, headers?: HttpHeaders): Scope;
|
||||
@@ -94,6 +94,7 @@ declare namespace nock {
|
||||
replyWithError(errorMessage: string | any): Scope;
|
||||
replyWithFile(responseCode: number, fileName: string, headers?: HttpHeaders): Scope;
|
||||
|
||||
matchHeader(name: string, value: string | RegExp | { (value: string): boolean; }): this;
|
||||
basicAuth(options: { user: string; pass?: string; }): this;
|
||||
|
||||
times(newCounter: number): this;
|
||||
|
||||
@@ -311,7 +311,7 @@ var scope = nock('http://www.google.com')
|
||||
/// Access original request and headers
|
||||
var scope = nock('http://www.google.com')
|
||||
.get('/cat-poems')
|
||||
.reply(function (uri, requestBody) {
|
||||
.reply(function(uri, requestBody) {
|
||||
console.log('path:', this.req.path);
|
||||
console.log('headers:', this.req.headers);
|
||||
// ...
|
||||
@@ -519,7 +519,7 @@ var scope = nock('http://api.myservice.com')
|
||||
.post('/', 'ABC')
|
||||
.reply(201, 'OK');
|
||||
|
||||
// Request Headers Matching
|
||||
// Request Headers Matching on the Scope Level
|
||||
var scope = nock('http://api.myservice.com')
|
||||
.matchHeader('accept', 'application/json')
|
||||
.get('/')
|
||||
@@ -543,6 +543,30 @@ var scope = nock('http://api.myservice.com')
|
||||
data: 'hello world'
|
||||
})
|
||||
|
||||
// Request Headers Matching on the Interceptor Level
|
||||
var scope = nock('http://api.myservice.com')
|
||||
.get('/')
|
||||
.matchHeader('accept', 'application/json')
|
||||
.reply(200, {
|
||||
data: 'hello world'
|
||||
})
|
||||
|
||||
var scope = nock('http://api.myservice.com')
|
||||
.get('/')
|
||||
.matchHeader('User-Agent', /Mozilla\/.*/)
|
||||
.reply(200, {
|
||||
data: 'hello world'
|
||||
})
|
||||
|
||||
var scope = nock('http://api.myservice.com')
|
||||
.get('/')
|
||||
.matchHeader('content-length', (val) => {
|
||||
return Number(val) >= 1000;
|
||||
})
|
||||
.reply(200, {
|
||||
data: 'hello world'
|
||||
})
|
||||
|
||||
// Allow unmocked requests on a mocked hostname
|
||||
options = {allowUnmocked: true};
|
||||
var scope = nock('http://my.existing.service.com', options)
|
||||
|
||||
+1
-66
@@ -1,80 +1,15 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"adjacent-overload-signatures": false,
|
||||
"array-type": false,
|
||||
"arrow-return-shorthand": false,
|
||||
"ban-types": false,
|
||||
"callable-types": false,
|
||||
"comment-format": false,
|
||||
"dt-header": false,
|
||||
"npm-naming": false,
|
||||
"eofline": false,
|
||||
"export-just-namespace": false,
|
||||
"import-spacing": false,
|
||||
"interface-name": false,
|
||||
"interface-over-type-literal": false,
|
||||
"jsdoc-format": false,
|
||||
"max-line-length": false,
|
||||
"member-access": false,
|
||||
"new-parens": false,
|
||||
"no-any-union": false,
|
||||
"no-boolean-literal-compare": false,
|
||||
"no-conditional-assignment": false,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"no-construct": false,
|
||||
"no-declare-current-package": false,
|
||||
"no-duplicate-imports": false,
|
||||
"no-duplicate-variable": false,
|
||||
"no-empty-interface": false,
|
||||
"no-for-in-array": false,
|
||||
"no-inferrable-types": false,
|
||||
"no-internal-module": false,
|
||||
"no-irregular-whitespace": false,
|
||||
"no-mergeable-namespace": false,
|
||||
"no-misused-new": false,
|
||||
"no-namespace": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-padding": false,
|
||||
"no-redundant-jsdoc": false,
|
||||
"no-redundant-jsdoc-2": false,
|
||||
"no-redundant-undefined": false,
|
||||
"no-reference-import": false,
|
||||
"no-relative-import-in-test": false,
|
||||
"no-self-import": false,
|
||||
"no-single-declare-module": false,
|
||||
"no-string-throw": false,
|
||||
"no-unnecessary-callback-wrapper": false,
|
||||
"no-unnecessary-class": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"no-unnecessary-qualifier": false,
|
||||
"no-unnecessary-type-assertion": false,
|
||||
"no-useless-files": false,
|
||||
"no-var-keyword": false,
|
||||
"no-var-requires": false,
|
||||
"no-void-expression": false,
|
||||
"no-trailing-whitespace": false,
|
||||
"object-literal-key-quotes": false,
|
||||
"object-literal-shorthand": false,
|
||||
"one-line": false,
|
||||
"one-variable-per-declaration": false,
|
||||
"only-arrow-functions": false,
|
||||
"prefer-conditional-expression": false,
|
||||
"prefer-const": false,
|
||||
"prefer-declare-function": false,
|
||||
"prefer-for-of": false,
|
||||
"prefer-method-signature": false,
|
||||
"prefer-template": false,
|
||||
"radix": false,
|
||||
"semicolon": false,
|
||||
"space-before-function-paren": false,
|
||||
"space-within-parens": false,
|
||||
"strict-export-declare-modifiers": false,
|
||||
"trim-file": false,
|
||||
"triple-equals": false,
|
||||
"typedef-whitespace": false,
|
||||
"unified-signatures": false,
|
||||
"void-return": false,
|
||||
"whitespace": false
|
||||
"strict-export-declare-modifiers": false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user