当我使用Qunit运行此测试时,我收到此错误“无法读取未定义的属性'数据源' 我的脚本正在加载,我验证了,我希望能够创建组合框,添加数据源,并验证我可以将数据绑定到该数据源
这是我的javascript文件中的测试代码:
/// <reference path="../qunit.js" />
/// <reference path="../jquery/jquery-2.0.3-vsdoc.js" />
/// <reference path="../jquery/jquery-2.0.3.js" />
/// <reference path="../jquery/jquery.validate.min.js" />
/// <reference path="../../../../web/scripts/Kendo/kendo.all.min.js" />
module("Kendo combo box testfunctions", {
setup: function () {
var Div = $("#Div1");
var selectItem = '<select id="combo"></select>';
var kendoCombo = $("#combo");
Div.append(selectItem);
kendoCombo.kendoComboBox({
dataTextField: "text",
dataValueField: "value",
dataSource: [
{ text: "Item1", value: "1" },
{ text: "Item2", value: "2" }
]
});
},
teardown: function () {
var div = $("#div1");
div1.remove();
}
});
test("kendo combo create", function () {
debugger
var dv= $("#div1");
$("#combo").kendoCombo.kendoComboBox({
dataTextField: "text",
dataValueField: "value",
dataSource: [
{ text: "Item1", value: "1" },
{ text: "Item2", value: "2" }
]
});
var combobox = $("#combo").data("kendoComboBox");
ok(combobox != undefined, "sucess Created kendo combo box");
});
这是我的HMTL文件:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<link href="../content/qunit.css" rel="stylesheet" />
<script src="../scripts/qunit.js"></script>
<script src="../scripts/unittests/sampletests.js"></script>
<script src="../scripts/jquery/jquery-2.0.3.min.js"></script>
<script type="text/javascript">
</script>
</head>
<body>
<h1 id="qunit-header">Unit Tests</h1>
<h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup, will be hidden</div>
<div id="div1">
</div>
</body>
</html>
答案 0 :(得分:0)
在你的测试中:
var k = $('#combo');
k.kendoCombo.kendoComboBox({
dataTextField: "text",
dataValueField: "value",
dataSource: [
{ text: "Item1", value: "1" },
{ text: "Item2", value: "2" }
]
});
var combobox = k.data("kendoComboBox").datasource;
您期望k.kendoCombo
是什么?你试图从k
获取小部件,所以你可能想在这个元素上创建你的组合框,即:
var k = $('#combo');
k.kendoComboBox({
dataTextField: "text",
dataValueField: "value",
dataSource: [
{ text: "Item1", value: "1" },
{ text: "Item2", value: "2" }
]
});
var combobox = k.data("kendoComboBox").dataSource; // also note the upper case S in the dataSource property
您的代码整体上非常混乱 - 为什么要将组合框数据源分配给combobox
var?