Coder Social home page Coder Social logo

phase-1-sending-data-with-fetch's Issues

Tests fail to pass even though it works as expected

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

> [email protected] 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

Missing the word 'us' in "enables to improve"

Canvas Link

https://learning.flatironschool.com/courses/5185/assignments/179314?module_item_id=396190

Concern

Missing the word 'us' in the following:
It also enables to improve our users' experience by rendering content without reloading the page.

Additional Context

No response

Suggested Changes

Instead of this:
It also enables to improve our users' experience by rendering content without reloading the page.

Maybe this:
It also enables us to improve our users' experience by rendering content without reloading the page.

Complex phrasing: "...specific headers the server is configured to expect"

Canvas Link

https://learning.flatironschool.com/courses/5185/assignments/179314?module_item_id=396190

Concern

This sentence seems more complex than necessary, maybe because of passive voice?
Servers may reject requests without the specific headers the server is configured to expect.

Mentally processing this logic seems like unnecessary overhead for comprehending this message.

Additional Context

No response

Suggested Changes

Instead of this:
Servers may reject requests without the specific headers the server is configured to expect.

Maybe this?:
A server that expects specific headers may reject requests that omit those headers.
Or: ... that don't include those headers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.