我有一个基于 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 执行正确的操作?