Unit testing Qunit Javascript单元测试

Unit testing Qunit Javascript单元测试,unit-testing,reference,lazy-loading,sample,qunit,Unit Testing,Reference,Lazy Loading,Sample,Qunit,我正在寻找关于如何使用Qunit框架为非结构化javascript客户端验证编写单元测试用例的参考: jQuery.validator.addMethod('requiredifnotempty', function(value, element, parameters) { var otherPropertyId = '#' + parameters['otherproperty']; // get the actual value of the other control

我正在寻找关于如何使用Qunit框架为非结构化javascript客户端验证编写单元测试用例的参考:

   jQuery.validator.addMethod('requiredifnotempty',
   function(value, element, parameters) {
   var otherPropertyId = '#' + parameters['otherproperty'];

// get the actual value of the other control
var otherControl = $(otherPropertyId);
var controlType = otherControl.prop('type');
var otherValue = otherControl.val();

if (controlType === 'checkbox') {
    otherValue = otherControl.prop("checked").toString();
}

if (otherValue.trim().length > 0) {
    return $.validator.methods.required.call(this, value, element, parameters);
}

return true;
}

 );
jQuery.validator.unobtrusive.adapters.add(
'requiredifnotempty',
 ['otherproperty'],
 function (options) {
    options.rules['requiredifnotempty'] = {
    otherproperty: options.params['otherproperty']
  };
   options.messages['requiredifnotempty'] = options.message;        
 });

以下是一些参考资料: