Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Drop support for String constructor (#1873)
BREAKING CHANGE: Drop support for String constructor (#1873)

When checking types of strings, Nock will no longer recognize the String constructor, only string primitives.
  • Loading branch information
paulmelnikow authored and gr2m committed Feb 16, 2020
1 parent 7fae3c8 commit e33b3e8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
4 changes: 1 addition & 3 deletions lib/back.js
@@ -1,7 +1,6 @@
'use strict'

const assert = require('assert')
const _ = require('lodash')
const recorder = require('./recorder')
const {
activate,
Expand Down Expand Up @@ -61,8 +60,7 @@ function Back(fixtureName, options, nockedFn) {
)
}

// TODO-12.x: Replace with `typeof fixtureName === 'string'`.
if (!_.isString(fixtureName)) {
if (typeof fixtureName !== 'string') {
throw new Error('Parameter fixtureName must be a string')
}

Expand Down
9 changes: 3 additions & 6 deletions lib/common.js
Expand Up @@ -174,8 +174,7 @@ function stringifyRequest(options, body) {

function isContentEncoded(headers) {
const contentEncoding = headers['content-encoding']
// TODO-12.x: Replace with `typeof contentEncoding === 'string'`.
return _.isString(contentEncoding) && contentEncoding !== ''
return typeof contentEncoding === 'string' && contentEncoding !== ''
}

function contentEncoding(headers, encoder) {
Expand Down Expand Up @@ -364,8 +363,7 @@ function deleteHeadersField(headers, fieldNameToDelete) {
throw Error('headers must be an object')
}

// TODO-12.x: Replace with `typeof fieldNameToDelete !== 'string'`.
if (!_.isString(fieldNameToDelete)) {
if (typeof fieldNameToDelete !== 'string') {
throw Error('field name must be a string')
}

Expand Down Expand Up @@ -446,8 +444,7 @@ function formatQueryValue(key, value, stringFormattingFn) {
case value === undefined:
value = ''
break
// TODO-12.x: Replace with `typeof value === 'string'`.
case _.isString(value):
case typeof value === 'string':
if (stringFormattingFn) {
value = stringFormattingFn(value)
}
Expand Down
4 changes: 1 addition & 3 deletions lib/intercept.js
Expand Up @@ -8,7 +8,6 @@ const { InterceptedRequestRouter } = require('./intercepted_request_router')
const common = require('./common')
const { inherits } = require('util')
const http = require('http')
const _ = require('lodash')
const debug = require('debug')('nock.intercept')
const globalEmitter = require('./global_emitter')

Expand Down Expand Up @@ -52,8 +51,7 @@ let allowNetConnect
* nock.enableNetConnect(/(google|amazon)/);
*/
function enableNetConnect(matcher) {
// TODO-12.x: Replace with `typeof matcher === 'string'`.
if (_.isString(matcher)) {
if (typeof matcher === 'string') {
allowNetConnect = new RegExp(matcher)
} else if (matcher instanceof RegExp) {
allowNetConnect = matcher
Expand Down

0 comments on commit e33b3e8

Please sign in to comment.