【问题标题】:zombie.js xhr json always fail僵尸.js xhr json 总是失败
【发布时间】:2015-04-28 20:49:32
【问题描述】:

我想用僵尸 js 来测试我的小节点应用程序。 我正在使用带有僵尸的模拟资源,但是当我写的时候

主体:对象

在 mock.the xhr 总是因为

而失败
Request Failed: parsererror, SyntaxError: Unexpected token o

当我写作时

正文:'json 内容'

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

【问题讨论】:

    标签: javascript jquery json zombie.js


    【解决方案1】:

    在应用程序中,我正在使用 Express 框架,并且我使用库中的数组 res.json。

    res.json 似乎将我的数组字符串化

    【讨论】:

      猜你喜欢
      • 2015-09-08
      • 1970-01-01
      • 1970-01-01
      • 2013-10-03
      • 2012-03-11
      • 1970-01-01
      • 2013-09-24
      • 2011-03-14
      • 1970-01-01
      相关资源
      最近更新 更多