Skip to content

Post requests failing in Nock beta 11 #1642

@alexlitel

Description

@alexlitel

What is the expected behavior?
Nock should successfully return a response for intercepted POST requests, including from external libraries for interfacing with an API, in this case @octokit/rest the Github REST API client. This is the behavior that occurs in Nock v10.

What is the actual behavior?
On Nock v11.0.0-beta.28, it does not successfully intercept and response to the POST requests, and throws RequestError: (headers.content-type || "").toLowerCase is not a function. It seems to stem from some inability to parse JSON data passed with the request. Longer stack trace from local with another REST API.

TypeError: (headers.content-type || "").toLowerCase is not a function
    at Object.isJSONContent (/Users/xx/xx/node_modules/nock/lib/common.js:188:55)
    at parseJSONRequestBody (/Users/xx/xx/node_modules/nock/lib/request_overrider.js:556:31)
    at end (/Users/xx/xx/node_modules/nock/lib/request_overrider.js:329:33)
    at /Users/xx/xx/node_modules/nock/lib/request_overrider.js:163:9
    at OverriddenClientRequest.RequestOverrider.req.write (/Users/xx/xx/node_modules/nock/lib/request_overrider.js:135:9)
    at OverriddenClientRequest.RequestOverrider.req.end (/Users/xx/xx/node_modules/nock/lib/request_overrider.js:159:11)
    at writeToStream (/Users/xx/xx/node_modules/node-fetch/lib/index.js:648:8)
    at /Users/xx/xx/node_modules/node-fetch/lib/index.js:1620:3
    at new Promise (<anonymous>)
    at fetch (/Users/xx/xx/node_modules/node-fetch/lib/index.js:1401:9)
    at fetch (/Users/xx/xx/node_modules/cross-fetch/dist/node-ponyfill.js:10:20)

Possible solution
Change how JSON data is parsed

How to reproduce the issue

Runkit: Working in Nock v10
Runkit: Not working in Nock v11

Does the bug have a test case?
See above

Versions

Software Version(s)
Nock 11.0.0-beta.28
Node 12.6.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions