我想創建一個測試用流星寫的API端點。我正在使用茉莉花和速度。它的目的是在同一個項目中運行,這就是我使用它們的原因。 當我試圖運行測試並檢查端點中的數據時,問題就出現了。我在MongoDB副本中有一個引導數據集,當我POST時,它與本地應用程序中引導的數據集不匹配。 這裏的示例代碼:流星集成測試,休息api終點在速度的鏡子與茉莉花
Jasmine.onTest(function() {
describe('RestApi.MyMethod', function() {
it('Expects to fail because it lacks of valid parameters', function() { /*but it fails because of the user can't be found in the real app*/
var response = "";
var userId = Meteor.users.findOne({"username": "MyUser"})._id;
try {
response = Meteor.http.call(
"POST",
"http://localhost:3000/api/myMethod",
{
data: {
"userId":
},
timeout: 1000
}
);
} catch(error){
expect(error.message.indexOf("failed [400]")).toBeGreaterThan(-1);
expect(error.message.indexOf("Invalid parameters provided")).toBeGreaterThan(-1);
}
expect(response).toBe('');
});
});
});
我認爲它應該指向鏡的REST API。有沒有辦法做到這一點?我將localhost:3000更改爲localhost:5000,但無效。我如何檢查鏡子的端口? 在此先感謝!
看起來像端口選項現在是自動的,並且不硬編碼爲5000.您可以使用JASMINE_SERVER_MIRROR_PORT env變量(在某些地方命名爲錯誤)配置端口。不知道是否有辦法讓鏡像在運行時運行測試,從而獲得IP和端口。 – LuisTensai 2015-03-31 17:30:26
如果你在'Meteor.http.call'中使用相對路徑怎麼辦? – raddevon 2015-04-01 03:04:59