【发布时间】:2015-06-05 02:24:08
【问题描述】:
我正在尝试为使用流星编写的 API 端点创建测试。我正在使用茉莉花和速度。它旨在在同一个项目中运行,这就是我使用它们的原因。 当我尝试运行测试并检查端点中的数据时,问题就出现了。我在 mongodb 副本中有一个引导数据集,当我发布它时,它与本地应用程序中引导的数据集不匹配。 下面是示例代码:
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 环境变量配置端口(在某些地方命名不好)。想知道是否有办法获取镜像在运行时运行测试的 ip 和端口。
-
如果在
Meteor.http.call中使用相对路径会怎样?
标签: javascript rest meteor meteor-velocity meteor-jasmine