【发布时间】:2015-05-04 13:29:44
【问题描述】:
我正在尝试测试 Backbone 集合的获取。我正在使用 Sinon 的假服务器来设置假 REST 端点。问题是请求似乎没有发送。
我正在使用 Jasmine 和 Karma 并通过 PhantomJS 运行它。
问题是请求显然没有被发送。没有任何错误,但没有任何内容记录到控制台。
代码如下:
describe("The Posts collection", function() {
var posts;
var server;
beforeEach(function() {
server = sinon.fakeServer.create();
posts = new PostCollection();
});
afterEach(function() {
server.restore();
});
it("should fetch the posts from the api", function() {
server.respondWith("GET", "/posts",
[200, { "Content-Type": "application/json" },
'{ "stuff": "is", "awesome": "in here" }']);
posts.fetch({
success: function(model, response, options) {
console.log("REQUEST SENT");
}
});
});
});
【问题讨论】:
标签: backbone.js jasmine karma-runner karma-jasmine sinon