【发布时间】:2013-02-11 15:26:31
【问题描述】:
我有一个基于 Backbone.Router 的 myRouter,它根据 URL 调用某些 set() 方法:
var MyRouter = Backbone.Router.extend({
routes: {
"doSomething/:value": "doSetterOnModel",
},
doSetterOnModel: function(value) {
// does some set(value) calls on my Model
},
});
我想现在使用 QUnit 测试测试模型是否正确更新(set()):
test( "update Model via URL change", function() {
var value = "newValue";
var url = "http://localhost/#/doSomething/" + value;
//does not work as it moves page away from QUnit's tests.html page
window.location = url;
// does also not work because it moves away from QUnit's tests.html page
myRouter.navigate(url);
deepEqual( myModel.get(key), value, "Value on Model was not updated by URL change");
});
如何在 Qunit 中设置 URL 以测试我的路由器是否对某个 URL 执行正确的操作?
【问题讨论】:
标签: backbone.js qunit backbone-routing