[英]Unit Testing Java Script - Fake XRM with QUnit
I have a js
function which I want to unit test using QUnit
. 我有一个
js
函数,我想使用QUnit
进行单元测试。 It is a simple function where I pass the field name that I want to hide from the form. 这是一个简单的函数,可在其中传递要从表单中隐藏的字段名称。 I am also using a Mocking framework from here: [link] https://github.com/ambek/XrmPage-Mock
我也在这里使用一个Mocking框架:[link] https://github.com/ambek/XrmPage-Mock
function HideField(field) {
Xrm.Page.getControl(field).setVisible(false);
};
My Tests.js file looks like this: 我的Tests.js文件如下所示:
var Xrm;
QUnit.test("Testing Hide Field Function", function (assert) {
var PageControls = new Array();
PageControls.push(CreateSimpleControlWithAttribute("NewField", "M", "Type of Residence"));
var page = new XrmPageMock("{607C16D1-7C53-4023-B20B-13E4F1C6A9D3}", PageControls, 1);
Xrm = new XrmPageMock(page);
HideField('NewField');
assert.equal(XRM.page.getControl('NewField').getVisible(),false, 'Passsed');
});
On executing my tests, I get this error: 在执行测试时,出现以下错误:
Unable to get property 'getControl' of undefined or null reference
无法获取未定义或空引用的属性“ getControl”
Does anyone know why my mocking/faking is going wrong? 有谁知道为什么我的嘲笑/假装出了错?
It was just a typo in the following statement: 以下陈述只是错字:
assert.equal(XRM.page.getControl('NewField').getVisible(),false, 'Passsed');
The new statement is (Correction on the word "page") 新的声明是(在“页面”一词上更正)
assert.equal(XRM.Page.getControl('NewField').getVisible(),false, 'Passsed');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.