0
我很新的摩卡/ omf。我有以下的基本测试:如何获得响应的身体与摩卡/ node.js
omf('http://localhost:7000', function(client) {
client.get('/apps', function(response){
response.has.statusCode(200);
response.has.body('["test1","test2"]');
});
});
我想检查是否值“TEST2”是返回的列表中,但我无法弄清楚如何,这是可行的。我正在考虑类似于:
omf('http://localhost:7000', function(client) {
client.get('/apps', function(response){
response.has.statusCode(200);
// response.body.split.contains("test2"); // Something like that
});
});
我可以访问response.body然后解析字符串吗?
**更新**
我试着摩卡测试,只是一个简单的状态代码:
request = require("request");
describe('Applications API', function(){
it('Checks existence of test application', function(done){
request
.get('http://localhost:7000/apps')
.expect(200, done);
});
});
,但我得到了以下错误:
TypeError: Object # has no method 'expect'
任何想法?摩卡需要额外的插件吗?
有你使用supertest考虑?这工作得很好。 – AndyD 2013-02-19 14:16:12
听起来很酷。它似乎能够匹配解析的身体对象...你有任何例子吗? – Luc 2013-02-19 15:44:50