samedi 23 janvier 2016

Mocha testing (POST requests): error outside of test suite

I've been thumping my head against a wall for the past day now. Can't figure out what might be throwing the error in Mocha: "Uncaught error outside test suite: Uncaught Error: connect ECONNREFUSED 127.0.0.1:27017" in Mocha.

The test passes, but it throws that error in red.

I am running a simple test for a POST request. There are no other instances of node, mongod or any other app running while testing. I also shut down the express server in an AFTER block to make sure it's done before the next time I try testing.

Code:

describe('UNIT: test the cat express app', () => {
  after((done) => {
    server.close();
    done();
  });

  it('should create with a new cat with a POST request', (done) => {
    chai.request('localhost:3000')
    .post('/app/cats')
    .send({name: 'test cat'})
    .end((err, res) => {
      expect(err).to.eql(null);
      expect(res).to.have.status(200);
      expect(res.body.name).to.eql('test cat');
      expect(res.body).to.have.property('_id');
      done();
    });
  });
});

Any advice at all would help. I've looked everywhere but haven't found anything besides just closing the server in an After block.

Aucun commentaire:

Enregistrer un commentaire