title: How to test upload file with mocha and chai?
body: <p>I am trying to test my nodejs API with <a href="https://mochajs.org/" rel="noreferrer">Mocha</a>/<a href="http://chaijs.com/" rel="noreferrer">Chai</a>. I created a "test" folder which contain File.js with this code inside :</p>
  
  <pre><code>let chai = require('chai');
  let chaiHttp = require('chai-http');
  
  let fs = require('fs');
  
  let should = chai.should();
  
  chai.use(chaiHttp);
  
  var fileName = 'devJoke.png';
  
  describe('/PUT file', () =&gt; {
      it('Should PUT a file', (done) =&gt; {
          let file = {
              fileName: "devJoke.png",
          }
          chai.request('http://localhost:3000')
              .put('/bucket/user2/files/')
              .set('secret_key', 'user2SecretKey')
              .set('Content-Type', 'application/x-www-form-urlencoded')
              .field('Content-Type', 'multipart/form-data')
              .field('fileName', 'devJoke.png')
              .attach('files', "/Users/stagiaire/Downloads/devJoke.png")
              .send(file)
              .end((err, res) =&gt; {
                  if (err) {
                      console.log(err)
                  } else {
  
                      res.should.have.status(200);
                      res.body.should.be.a('object');
                      res.body.should.have.property('data').eql('File Uploaded')
                  }
                  done();
              })
      })
  })
  </code></pre>
  
  <p>But when I am doing the command npm test, I got the error 
      <code>{ 
      Error: read ECONNRESET
      at _errnoException (util.js:1019:11)
      at TCP.onread (net.js:608:25)
      code: 'ECONNRESET',
      errno: 'ECONNRESET',
      syscall: 'read',
      response: undefined }</code></p>
  
  <p>With PostMan I used headers with :</p>
  
  <pre><code>{"Content-Type":"application/x-www-form-urlencoded"}
  {"secret_key":"user2SecretKey"}
  </code></pre>
  
  <p>And got this on body :</p>
  
  <pre><code>{"fileName":"devJoke.png"}
  {"files": myFile}
  </code></pre>
  
  <p>It worked with PostMan and I tried to do the same with mocha/chai. What have I done wrong? </p>