我想使用僵尸js来测试我的小节点应用程序。我对僵尸使用了模拟资源,但当我写下
正文:对象
在mock.the中,xhr总是失败,因为
Request Failed: parsererror, SyntaxError: Unexpected token o当我写的时候
body:'json content‘
xhr工作良好
要测试此客户端js,请执行以下操作
var xhrGetRiver = $.getJSON("api/1/settings/rivers/fs/")
xhrGetRiver.done(function(json) {
console.log(json);
$.each(json, function(index, fsriver) {
insertFSRiver(fsriver);
});
});
xhrGetRiver.fail(function(jqxhr, textStatus, error) {
var err = textStatus + ', ' + error;
console.log("Request Failed: " + err);
});
我写了这个测试
var data = [];
var json = {
"id": "test",
"properties": {
"url": "/tmp",
"server": "192.168.9.2",
"port": 22,
"username": "testUser",
"password": "test",
"protocol": "ssh",
"update_rate": "15m",
"includes": "*.docx"
}
};
data.push(json);
this.browser.resources.mock('/api/1/settings/rivers/fs/', {
statusCode: 200,
headers: { 'ContentType': 'application/json' },
body: data // xhr fail
//body: '[ { "id":... ... } ]' // Work well
发布于 2015-02-26 21:18:03
在app中,我使用的是Express框架,我使用的是库中的数组res.json。
res.json似乎将我的数组串化了
https://stackoverflow.com/questions/28743091
复制相似问题