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

Tests fail to pass even though it works as expected #8

Closed
alandio opened this issue Nov 3, 2022 · 6 comments
Closed

Tests fail to pass even though it works as expected #8

alandio opened this issue Nov 3, 2022 · 6 comments
Labels
se curriculum Issue for lessons in the Software Engineering program

Comments

@alandio
Copy link

alandio commented Nov 3, 2022

Canvas Link

https://my.learn.co/courses/590/assignments/27782?module_item_id=68707

Concern

I've solved the assignment, but for some reason I still get an error. I don't think the error is related to the code I've written but more the test or something in node-fetch package has change maybe?

Here is the error:

npm test

> javascript-lab@1.0.0 test
> mocha --timeout 5000 -R mocha-multi --reporter-options spec=-,json=.results.json



  submitData()
(node:1083030) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
(Use `node --trace-deprecation ...` to show where the warning was created)
    1) makes a POST request to /users with a name and email
    ✓ makes a POST request to /users with a name and email
    ✓ handles a failed POST request using catch, appends the error message to the DOM
    ✓ handles a failed POST request using catch, appends the error message to the DOM


  3 passing (301ms)
  1 failing

  1) submitData()
       makes a POST request to /users with a name and email:
     Uncaught TypeError [ERR_INVALID_ARG_TYPE]: The "stream" argument must be an instance of Stream. Received an instance of Socket
      at new NodeError (node:internal/errors:393:5)
      at eos (node:internal/streams/end-of-stream:65:11)
      at IncomingMessage._destroy (node:_http_incoming:234:21)
      at _destroy (node:internal/streams/destroy:109:10)
      at IncomingMessage.destroy (node:internal/streams/destroy:71:5)
      at endReadableNT (node:internal/streams/readable:1375:16)
      at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

This is after writing my code and running npm install then npm test.
Here is my code:

const submitData = (username, email) => {
    const formData = {
        name: username,
        email: email
    };

    const configurationObject = {
        method: "POST",
        headers: {
            "Content-Type": "application/json",
            Accept: "application/json",
        },
        body: JSON.stringify(formData)
    };

    const destinationURL = "http://localhost:3000/users";

    return fetch(destinationURL, configurationObject)
        .then(response => response.json())
        .then(object => document.body.innerHTML = object["id"])
        .catch(error => document.body.innerHTML = error.message);
}

Additional Context

node version: v19.0.0

Suggested Changes

No response

@alandio alandio added the se curriculum Issue for lessons in the Software Engineering program label Nov 3, 2022
@miShelbyT
Copy link

Just wanted to echo this error. I am experiencing it as well: Uncaught TypeError [ERR_INVALID_ARG_TYPE]: The "stream" argument must be an instance of Stream. Received an instance of Socket.
I don't know much about Stream instances. Reading this resource and feeling confused as to why we are getting a websocket instead of a Stream instance?

@ocole161
Copy link

Had the same issue.

@zigzagoon1
Copy link

I had the same problem!

@sheenasany
Copy link

sheenasany commented Jan 31, 2023

Still having this error with students who are trying to pass the first test, even though the post request is working on the DOM.

Uncaught TypeError [ERR_INVALID_ARG_TYPE]: The "stream" argument must be an instance of Stream. Received an instance of Socket

A suggestion that could fix this issue would be to downgrade your node version. Like so:
nvm install 16.14.2
nvm alias default 16.14.2

Or! If you're still working on this lab, just want to downgrade your current version just for this lab, try this:
nvm install 16.14.2
nvm use 16.14.2

You could also delete the node modules and the package-lock file and reinstall dependencies.

That should fix the issue and get the tests to pass or just make the tests easier to read.

@codified45
Copy link

Issue still persists.

Downgrading node to 16.14.2 as referenced above did the trick. Thanks for the advice!
You can check your version of node by running this command in your terminal:

node -v

and then you can downgrade with these commands:

nvm install 16.14.2
nvm use 16.14.2

then after you complete the lab you can change back to your current version:

nvm use [version number listed when you ran first command]

@lizbur10
Copy link
Contributor

Hey all! Thanks for all the help with this issue. It should now be fixed and should work with either Node 16 or Node 18 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
se curriculum Issue for lessons in the Software Engineering program
Projects
None yet
Development

No branches or pull requests

7 participants