我有一个问题是让qunit和resharper识别visual studio中的某些视图模型。我确信这取决于我的文件分离,但我无法确切地知道它是什么。工作小提琴在这里:http://jsfiddle.net/9nfzS/1/
当我将测试与viewmodel分开时,会出现问题。这些文件属于不同的项目(但是当它们在同一个项目中时,也会出现问题,只是不同的文件)。文件内容如下:
ListTests.js
/// <reference path="List.js" />
/// <reference path="../../Scripts/knockout-3.1.0.js" />
/// <reference path="../../Scripts/jquery-2.1.0.js" />
$(function() {
module("test desk retrieval");
test("initial item length", function () {
QUnit.equal(deskns.viewmodel.desks().length, 0, "desks length");
});
test("initial description is empty", function () {
QUnit.equal(deskns.viewmodel.newDescription(), '', "new description");
});
test("does this work at all", function () {
QUnit.equal(1, 1);
});
});
List.js
var deskns = deskns || {};
$(function () {
ko.applyBindings(deskns.viewmodel);
});
deskns.DeskItem = function (params) {
params = params || {};
this.id = ko.observable(params.ID || '');
this.name = ko.observable(params.name || "<New>");
this.description = ko.observable(params.description || "<New>");
this.memberCount = ko.observable(params.memberCount || 0);
this.isActive = ko.observable(params.isActive || true);
}
deskns.viewmodel = (function () {
var
desks = ko.observableArray(),
addDesk = function () {
desks.push(new deskns.DeskItem({ name: newName(), description: newDescription() }));
clearInputs();
},
clearInputs = function () {
newName('');
newDescription('');
},
newName = ko.observable(""),
newDescription = ko.observable("");
return {
desks: desks,
add: addDesk,
newName: newName,
newDescription: newDescription
}
})();
参考路径是正确的,但在resharper runner中运行这些测试会产生错误:
Died on test #1: Cannot call method 'newDescription' of undefined - {}
Died on test #1: Cannot call method 'desks' of undefined - {}
所以viewmodel是未定义的。小提琴中的相同代码完美无缺,底层代码也按预期工作,我无法进行任何测试。有没有人知道这是什么 - 它一直让我绝对疯狂。