[英]How to write Mocha test case for HTML elements?
I am testing my JavaScript
code with Mocha / PhantomJS
setup to run the tests. 我正在用
Mocha / PhantomJS
安装程序测试我的JavaScript
代码以运行测试。
There is a function: 有一个功能:
function getNodeClickWithExpand(idElement, treeName, autoCompleteName) {
jQuery("input[type='checkbox'][name='c_" + idElement + "']").trigger("click");
var treeView = jQuery("#" + treeName).data("kendoTreeView");
treeView.expand(document.getElementById(idElement));
jQuery("#" + idElement).closest("div").find("span:last").addClass("k-state-selected");
kendoUiHoverAutoScrolling(idElement, treeName, autoCompleteName);
}
I am writing a test case for this function in Mocha
: 我正在
Mocha
为此功能编写一个测试用例:
describe("getNodeClickWithExpand", function () {
it("should pass with correct inputs", function () {
var processJsonObject = getNodeClickWithExpand(idElement, treeName, autoCompleteName);
console.log(processJsonObject);
});
});
when I run this test case it gives me an error. 当我运行这个测试用例时,它给我一个错误。 I know this is not correct.
我知道这是不正确的。 Please tell me how to run
test case for HTML elements and events
. 请告诉我如何
test case for HTML elements and events
运行test case for HTML elements and events
。
EDIT: 编辑:
Error I am getting: 我得到的错误:
I believe the issue is here- 我相信问题在这里-
it("should pass with correct inputs", function () {
var processJsonObject = getNodeClickWithExpand(idElement, treeName, autoCompleteName);
The test error 'Cannot read property 'expand' of null' indicates that there is no element in the dom with id = idElement. 测试错误“无法读取属性'expand'为null”表示在dom中没有id = idElement的元素。 You need to pass an element's id as a string when you are running the test.
运行测试时,您需要将元素的ID作为字符串传递。 You are also not passing any value for the parameters 'treeName' and 'autoCompleteName'.
您也不会传递任何参数'treeName'和'autoCompleteName'的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.