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

Got.js throws ERR_INVALID_ARG_TYPE when mocking with nock on Node 12.x #817

Closed
2 tasks done
yamalight opened this issue Jun 3, 2019 · 5 comments
Closed
2 tasks done

Comments

@yamalight
Copy link

Describe the bug

  • Node.js version: 12.x
  • OS & version: any

Trying to use nock with Got in Node 12.x breaks Got with ERR_INVALID_ARG_TYPE.

Actual behavior

When mocking API with nock.js - on request Got.js throws ERR_INVALID_ARG_TYPE and dies.

Expected behavior

Should correctly handle request to nock server.

Code to reproduce

const nock = require('nock');
const got = require('got');

const thisWorks = await got('https://httpbin.org/get');
console.log(thisWorks.body);

const testServer = nock('http://localhost:8080')
    .get('/')
    .reply(200, {hello: 'world'});

const thisBreaks = await got('http://localhost:8080/');
console.log(thisBreaks.body);

Here's an interactive demo:
https://runkit.com/yamalight/5cf50559b975d2001a4dfaa8

Switching to Node 10.x fixes the issue. Using e.g. node-fetch instead of Got.js also works correctly with nock.

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Got.
@sindresorhus
Copy link
Owner

Are you sure it's not nock/nock#1509?

@yamalight
Copy link
Author

@sindresorhus yes, I've tried using other libs and they seem to work fine.
I've added node-fetch and axios to interactive demo to demonstrate that they work fine.

@szmarczak
Copy link
Collaborator

szmarczak commented Jun 3, 2019

Make sure you're running at least 11.0.0-beta.13 (or above): nock/nock#1509 (comment)
The RunKit demo runs 10.0.6 where the issue is not fixed.

Let us know then.

@yamalight
Copy link
Author

@szmarczak yep, that does indeed fixes it. Somehow misread it and thought fix was shipped in 10.0.6. Sorry for the bother and thanks for help! 😅

@szmarczak
Copy link
Collaborator

No problem :)

solidgoldpig added a commit to ministryofjustice/fb-jwt-client-node that referenced this issue Jul 5, 2019
iancw added a commit to iancw/sermon-emails that referenced this issue Jan 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants