Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensure that falsy response bodies are correctly handled #2454

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/scope.js
Expand Up @@ -368,7 +368,7 @@ function define(nockDefs) {
// Response is not always JSON as it could be a string or binary data or
// even an array of binary buffers (e.g. when content is encoded).
let response
if (!nockDef.response) {
if (typeof nockDef.response === undefined) {
response = ''
// TODO: Rename `responseIsBinary` to `responseIsUtf8Representable`.
} else if (nockDef.responseIsBinary) {
Expand Down
16 changes: 16 additions & 0 deletions tests/test_scope.js
Expand Up @@ -8,6 +8,7 @@ const url = require('url')
const Interceptor = require('../lib/interceptor')
const nock = require('..')
const got = require('./got_client')
const { define } = require("../lib/scope")

it('scope exposes interceptors', () => {
const scopes = nock.load(
Expand Down Expand Up @@ -136,6 +137,21 @@ describe('`Scope#isDone()`', () => {
})
})

describe('`define()`', function () {
it("accurately sets interceptor response when value is `false`", function () {
const [scope] = define([{
"scope": "http://www.example.test:80",
"method": "GET",
"path": "/",
"body": "",
"status": 200,
"response": false,
}])

expect(scope.interceptors[0].body).to.be.false()
})
})

describe('`filteringPath()`', function () {
it('filter path with function', async function () {
const scope = nock('http://example.test')
Expand Down