2016-11-30 118 views
0

我是新來的摩卡和supertest,我試圖測試我的API,但我總是得到連接拒絕錯誤。錯誤:連接ECONNREFUSED,摩卡,超棒


 
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); 
 
    }); 
 
});

可不可以給任何線索,爲什麼這個happend? ,非常感謝

回答

-1

如果你想使用supertest庫,你必須暴露注入您的應用程序(express)不是一個URL(因爲你不會有一個活躍的服務器監聽):

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); 
    }); 
    }); 
});