0

I'm new to mocha and supertest , I'm trying to test my API but I always get connection refused error .

  
var request = require('supertest');

 it("posts a new comment to /comment", function (done) {
    var comment = { username: 'riheb', userId: 'test1', userPhotoId: '12a', comment: 'update file  now' };

    request("http://localhost:3000")
      .post("/sp/place/582f148515035818e080e653/folder/582f16b3ef9caf029863331b/file/583d6b5243af5628b8491fd3/comment")
      .send(comment)
      .expect(200)
      .expect(" riheb comment is stored", done);
  });
});

Could you give any clue why this happend? With Thanks

Safa
  • 107
  • 2
  • 9

1 Answers1

-1

If you want to use supertest library, you have to expose and inject your app (express) not a url (because you won't have an active server listening):

var request = require('supertest');
var app = require('../yourappexposed');

describe("Comments", function() {
 it("posts a new comment to /comment", function (done) {
    var comment = { username: 'riheb', userId: 'test1', userPhotoId: '12a', comment: 'update file  now' };
    request(app)
      .post("/sp/place/582f148515035818e080e653/folder/582f16b3ef9caf029863331b/file/583d6b5243af5628b8491fd3/comment")
      .send(comment)
      .expect(200)
      .expect(" riheb comment is stored", done);
    });
  });
});
Dario
  • 3,905
  • 2
  • 13
  • 27