Best JavaScript code snippet using sinon
spy-test.js
Source:spy-test.js
...158 assert(this.spy[method](1, 2, 3));159 });160 };161}162function verifyFunctionName(func, expectedName) {163 var descriptor = Object.getOwnPropertyDescriptor(func, "name");164 if (descriptor && descriptor.configurable) {165 // IE 11 functions don't have a name.166 // Safari 9 has names that are not configurable.167 assert.equals(descriptor.value, expectedName);168 assert.equals(func.name, expectedName);169 }170}171//eslint-disable-next-line mocha/max-top-level-suites172describe("spy", function() {173 it("does not throw if called without function", function() {174 refute.exception(function() {175 createSpy();176 });177 });178 it("does not throw when calling anonymous spy", function() {179 var spy = createSpy();180 refute.exception(spy);181 assert(spy.called);182 });183 it("returns spy function", function() {184 var func = function() {185 return;186 };187 var spy = createSpy(func);188 assert.isFunction(spy);189 refute.same(func, spy);190 });191 it("mirrors custom properties on function", function() {192 var func = function() {193 return;194 };195 func.myProp = 42;196 var spy = createSpy(func);197 assert.equals(spy.myProp, func.myProp);198 });199 it("does not define create method", function() {200 var spy = createSpy();201 assert.isUndefined(spy.create);202 });203 it("does not overwrite original create property", function() {204 var func = function() {205 return;206 };207 var object = (func.create = {});208 var spy = createSpy(func);209 assert.same(spy.create, object);210 });211 it("sets up logging arrays", function() {212 var spy = createSpy();213 assert.isArray(spy.args);214 assert.isArray(spy.returnValues);215 assert.isArray(spy.thisValues);216 assert.isArray(spy.exceptions);217 });218 it("works with getters", function() {219 var object = {220 get property() {221 return 42;222 }223 };224 var spy = createSpy(object, "property", ["get"]);225 assert.equals(object.property, 42);226 assert(spy.get.calledOnce);227 });228 it("works with setters", function() {229 var object = {230 get test() {231 return this.property;232 },233 set test(value) {234 this.property = value * 2;235 }236 };237 var spy = createSpy(object, "test", ["set"]);238 object.test = 42;239 assert(spy.set.calledOnce);240 assert(spy.set.calledWith(42));241 assert.equals(object.test, 84);242 assert.equals(object.property, 84);243 });244 it("works with setters and getters combined", function() {245 var object = {246 get test() {247 return this.property;248 },249 set test(value) {250 this.property = value * 2;251 }252 };253 var spy = createSpy(object, "test", ["get", "set"]);254 object.test = 42;255 assert(spy.set.calledOnce);256 assert.equals(object.test, 84);257 assert(spy.get.calledOnce);258 });259 describe("global.Error", function() {260 beforeEach(function() {261 this.originalError = globalContext.Error;262 });263 afterEach(function() {264 globalContext.Error = this.originalError;265 });266 it("creates a spy for Error", function() {267 refute.exception(function() {268 createSpy(globalContext, "Error");269 });270 });271 });272 it("should work with combination of withArgs arguments and order of calling withArgs", function() {273 function assertSpy(spy) {274 // assert callCount275 assert.equals(spy.callCount, 4);276 assert.equals(spy.withArgs(1).callCount, 3);277 assert.equals(spy.withArgs(1, 1).callCount, 1);278 assert.equals(spy.withArgs(1, 2).callCount, 1);279 // assert call280 assert.isUndefined(spy.getCall(0).args[0]);281 assert.equals(spy.getCall(1).args[0], 1);282 assert.isUndefined(spy.getCall(1).args[1]);283 assert.equals(spy.getCall(2).args[0], 1);284 assert.equals(spy.getCall(2).args[1], 1);285 assert.isUndefined(spy.getCall(2).args[2]);286 assert.equals(spy.getCall(3).args[0], 1);287 assert.equals(spy.getCall(3).args[1], 2);288 assert.isUndefined(spy.getCall(3).args[2]);289 ["args", "callId"].forEach(function(propName) {290 assert.equals(spy.withArgs(1).getCall(0)[propName], spy.getCall(1)[propName]);291 assert.equals(spy.withArgs(1).getCall(1)[propName], spy.getCall(2)[propName]);292 assert.equals(spy.withArgs(1).getCall(2)[propName], spy.getCall(3)[propName]);293 assert.isNull(spy.withArgs(1).getCall(3));294 assert.equals(spy.withArgs(1, 1).getCall(0)[propName], spy.getCall(2)[propName]);295 assert.isNull(spy.withArgs(1, 1).getCall(1));296 assert.equals(spy.withArgs(1, 2).getCall(0)[propName], spy.getCall(3)[propName]);297 assert.isNull(spy.withArgs(1, 2).getCall(1));298 });299 // assert firstCall, secondCall, thirdCall, and lastCall300 assert.equals(spy.firstCall.callId, spy.getCall(0).callId);301 assert.equals(spy.secondCall.callId, spy.getCall(1).callId);302 assert.equals(spy.thirdCall.callId, spy.getCall(2).callId);303 assert.equals(spy.lastCall.callId, spy.getCall(3).callId);304 assert.equals(spy.withArgs(1).firstCall.callId, spy.withArgs(1).getCall(0).callId);305 assert.equals(spy.withArgs(1).secondCall.callId, spy.withArgs(1).getCall(1).callId);306 assert.equals(spy.withArgs(1).thirdCall.callId, spy.withArgs(1).getCall(2).callId);307 assert.equals(spy.withArgs(1).lastCall.callId, spy.withArgs(1).getCall(2).callId);308 assert.equals(spy.withArgs(1, 1).firstCall.callId, spy.withArgs(1, 1).getCall(0).callId);309 assert.isNull(spy.withArgs(1, 1).secondCall);310 assert.isNull(spy.withArgs(1, 1).thirdCall);311 assert.equals(spy.withArgs(1, 1).lastCall.callId, spy.withArgs(1, 1).getCall(0).callId);312 assert.equals(spy.withArgs(1, 2).firstCall.callId, spy.withArgs(1, 2).getCall(0).callId);313 assert.isNull(spy.withArgs(1, 2).secondCall);314 assert.isNull(spy.withArgs(1, 2).thirdCall);315 assert.equals(spy.withArgs(1, 2).lastCall.callId, spy.withArgs(1, 2).getCall(0).callId);316 }317 var object = {318 f1: function() {319 return;320 },321 f2: function() {322 return;323 }324 };325 // f1: the order of withArgs(1), withArgs(1, 1)326 var spy1 = createSpy(object, "f1");327 assert.equals(spy1.callCount, 0);328 assert.equals(spy1.withArgs(1).callCount, 0);329 assert.equals(spy1.withArgs(1, 1).callCount, 0);330 assert.isNull(spy1.getCall(0));331 assert.isNull(spy1.getCall(1));332 assert.isNull(spy1.getCall(2));333 assert.isNull(spy1.getCall(3));334 object.f1();335 object.f1(1);336 object.f1(1, 1);337 object.f1(1, 2);338 assertSpy(spy1);339 // f2: the order of withArgs(1, 1), withArgs(1)340 var spy2 = createSpy(object, "f2");341 assert.equals(spy2.callCount, 0);342 assert.equals(spy2.withArgs(1, 1).callCount, 0);343 assert.equals(spy2.withArgs(1).callCount, 0);344 assert.isNull(spy2.getCall(0));345 assert.isNull(spy2.getCall(1));346 assert.isNull(spy2.getCall(2));347 assert.isNull(spy2.getCall(3));348 object.f2();349 object.f2(1);350 object.f2(1, 1);351 object.f2(1, 2);352 assertSpy(spy2);353 });354 describe(".named", function() {355 it("sets name and displayName", function() {356 var spy = createSpy();357 var retval = spy.named("beep");358 assert.equals(spy.displayName, "beep");359 verifyFunctionName(spy, "beep");360 assert.same(spy, retval);361 });362 });363 describe("call", function() {364 it("calls underlying function", function() {365 var called = false;366 var spy = createSpy(function() {367 called = true;368 });369 spy();370 assert(called);371 });372 it("passes 'new' to underlying function", function() {373 function TestClass() {374 return;375 }376 var SpyClass = createSpy(TestClass);377 var instance = new SpyClass();378 assert(instance instanceof TestClass);379 });380 it("passs arguments to function", function() {381 var actualArgs;382 var func = function(a, b, c, d) {383 actualArgs = [a, b, c, d];384 };385 var args = [1, {}, [], ""];386 var spy = createSpy(func);387 spy(args[0], args[1], args[2], args[3]);388 assert.equals(actualArgs, args);389 });390 it("maintains this binding", function() {391 var actualThis;392 var func = function() {393 actualThis = this;394 };395 var object = {};396 var spy = createSpy(func);397 spy.call(object);398 assert.same(actualThis, object);399 });400 it("returns function's return value", function() {401 var object = {};402 var func = function() {403 return object;404 };405 var spy = createSpy(func);406 var actualReturn = spy();407 assert.same(actualReturn, object);408 });409 it("throws if function throws", function() {410 var err = new Error();411 var spy = createSpy(function() {412 throw err;413 });414 assert.exception(spy, err);415 });416 it("retains function name", function() {417 function test() {418 return;419 }420 var spy = createSpy(test);421 assert.equals(spy.displayName, "test");422 verifyFunctionName(spy, "test");423 });424 it("retains function length 0", function() {425 var spy = createSpy(function() {426 return;427 });428 assert.equals(spy.length, 0);429 });430 it("retains function length 1", function() {431 // eslint-disable-next-line no-unused-vars432 var spy = createSpy(function(a) {433 return;434 });435 assert.equals(spy.length, 1);436 });...
ComboBox.js
Source:ComboBox.js
1/**2 * ä¸ææ¡æ§ä»¶ç»ä¸API3 *4 *5 */6wis.widget.ComboBox = function () {7 this._version = '1.0';89};1011wis.widget.ComboBox.prototype = {1213 _name: null,14 _isMultiSelect: null,15 _mode: null, //normal æ®é tree æ grid å表16 _selectData : null,17 _gridColumn : null, //å¦æmodeæ¯grid éè¦è®¾ç½®è¯¥å±æ§18 _treeData: null, //å¦æmodeæ¯tree éè¦è®¾ç½®è¯¥å±æ§19 _readonly: null,20 _values: null,21 _split: null, //åé符22 _selectExt: null, //æ¯å¦å±å¼ä¸ææ¡23 _onBeforeSelect:null,24 _onSelected:null,2526 _input: null,27 _table: null,28 _select: null,29 _grid:null,30 _domSelect: null,31 _renderFlag:null,3233 getReadonly: function () {34 return this._readonly || false;35 },36 setReadonly: function (readonly) {37 this._readonly = readonly;38 },3940 /**41 [42 { value: 1, name: "éæºç§æ"},43 { value: 2, name: "éæºæè²"},44 { value: 3, name: "éæºæèµ"},45 { value: 4, name: "éæºæºè½"}46 ]47 */48 getSelectData:function (){49 return this._selectData || [];50 },51 setSelectData:function (selectData){52 this._selectData = selectData;53 },5455 getName: function () {56 return this._name;57 },5859 setName: function (name) {60 this._name = name;61 },6263 getIsMultiSelect: function () {64 return this._isMultiSelect || false;65 },6667 setIsMultiSelect: function (isMultiSelect) {68 this._isMultiSelect = isMultiSelect;69 },7071 getMode: function () {72 return this._mode || 'normal';73 },7475 setMode: function (mode) {76 this._mode = mode;77 },7879 setValues: function(values) {80 this._values = values;81 },8283 getValues: function() {84 return this._values || [];85 },8687 setSplit: function(split) {88 this._split = split;89 },9091 getSplit: function() {92 return this._split || ',';93 },9495 setSelectExt: function(selectExt) {96 this._selectExt = selectExt;97 },9899 getSelectExt: function() {100 return this._selectExt || false;101 },102103 setTreeData: function(treeData) {104 this._treeData = treeData;105 },106107 /**108 [109 { text: 'èç¹1', children: [110 { text: 'èç¹1.1' },111 { text: 'èç¹1.2' },112 { text: 'èç¹1.3', children: [113 { text: 'èç¹1.3.1' ,children: [114 { text: 'èç¹1.3.1.1' },115 { text: 'èç¹1.3.1.2' }]116 },117 { text: 'èç¹1.3.2' }118 ]119 },120 { text: 'èç¹1.4' }121 ]122 },123 { text: 'èç¹2' },124 { text: 'èç¹3' },125 { text: 'èç¹4' }126 ]127 */128 getTreeData: function() {129 return this._treeData || {};130 },131132 /*133 [134 { header: 'ID', name: 'value', width: 30 },135 { header: 'åå', name: 'name' },136 { header: 'æ§å«', name: 'sex' }137 ];138 */139 getGridColumn: function () {140 return this._gridColumn || [];141 },142 setGridColumn: function (gridColumn) {143 this._gridColumn = gridColumn;144 },145146 /**147 * åå§åæ¹æ³148 */149 _init: function (data) {150151 },152153 /**154 * åå§å渲ææ¹æ³ ä»
å¨ç¬¬ä¸æ¬¡è°ç¨renderæ¶æ§è¡155 */156 _initRender: function () {157 var _this = this;158 this._domInput = jQuery('<div class="l-text l-text-combobox" style="width: 70px;">'159 +'<input type="text" class="l-text-field" style="width: 50px;">'160 +'<div class="l-trigger">'161 +'<div class="l-trigger-icon"></div>'162 +'</div>'163 +'<div class="l-trigger l-trigger-cancel" style="display: none;">'164 +'<div class="l-trigger-icon"></div>'165 +'</div>'166 +'</div>');167168 this._input = jQuery('input:first',this._domInput);169 this._input.mousedown(function(event){170 event.stopPropagation();171 if(_this.getReadonly()==false){172 if(_this.getSelectExt()==true){173 _this.setSelectExt(false);174 }else{175 _this.setSelectExt(true);176 }177 }else{178 _this.setSelectExt(false);179 }180 _this.render();181 });182 var divBtn = jQuery('div[class=l-trigger]:first',this._domInput);183 divBtn.hover(function (e){184 event.stopPropagation();185 this.className = 'l-trigger-hover';186 }, function (e){187 event.stopPropagation();188 this.className = 'l-trigger';189 });190 divBtn.mousedown(function(event){191 event.stopPropagation();192 if(_this.getReadonly()==false){193 if(_this.getSelectExt()==true){194 _this.setSelectExt(false);195 }else{196 _this.setSelectExt(true);197 }198 _this.render();199 }200 });201 this.getDomInstance().append(this._domInput);202 },203204 // 渲æåå¤çæ¹æ³205 _beforeRender: function () {206 this._renderFlag = true;207208 var _this = this;209210 //å¦æä¸ææ¡ä¸ä¸ºç©º åæ¸
空ä¸ææ¡211 if(this._select!=null){212 this._select.empty();213 }214 if(this.getMode()=='normal'){215 //åå§åä¸ææ¡div216 if(this._domSelect==null){217 this._domSelect = jQuery('<div class="l-box-select" style="width: 300px; display: none;">'218 +'<div class="l-box-select-inner" style="height: auto;"></div>'219 +'<div class="l-btn-nw-drop"></div>'220 +'</div>');221 this._domSelect.hover(null, function (e){222 event.stopPropagation();223 _this.setSelectExt(false);224 _this.render();225 });226 this._select = jQuery('div[class=l-box-select-inner]:first',this._domSelect);227 this.getDomInstance().append(this._domSelect);228 }229 //ææ¬æ¡æ¾ç¤ºéä¸å¼230 this._input.val(this.getTexts());231 //åå§åè¡¨æ ¼232 var table = jQuery('<table cellpadding="0" cellspacing="0" border="0" class="l-box-select-table l-table-nocheckbox"><tbody></tbody></table>');233 var data = this.getSelectData();234 var tbody = jQuery('tbody:first',table);235 for(var i=0;i<data.length;i++){236 var value = data[i]['value'];237 var name = data[i]['name'];238 var tr = jQuery('<tr align="left"><td></td></tr>');239 var td = jQuery('td:first',tr);240 td.attr('value',value).html(name);241 tbody.append(tr);242 }243 jQuery("td", tbody).click(function(){244 if(_this.getReadonly()==false){245 var values = _this.getValues();246 var value = jQuery(this).attr("value");247 var flag = true;248 if(_this._onBeforeSelect){249 flag = _this._onBeforeSelect(values);250 }251 if(flag){ //å¦æè¿åå¼ä¸ºtrue å继ç»æ§è¡252 var idx = jQuery.inArray(value,values);253 if(idx>-1){254 if(_this.getIsMultiSelect()==false){255 values = [];256 }else{257 values.splice(idx,1);258 }259 }else{260 if(_this.getIsMultiSelect()==false){261 values = [];262 }263 values.push(value);264 }265 _this.setValues(_this._arrayUnique(values));266 _this.setSelectExt(false);267 _this.render();268 if(_this._onSelected){269 _this._onSelected(values);270 }271 }272 }273 });274 //设置éä¸é¡¹é«äº®275 jQuery("td", tbody).removeClass("l-selected");276 for(var i=0;i<this.getValues().length;i++){277 jQuery('td[value='+this.getValues()[i]+']', tbody).addClass("l-selected");278 }279 this._select.append(table);280 //æ¾ç¤ºæéèä¸ææ¡281 if(this.getSelectExt()==true){282 this._domSelect.show();283 }else{284 this._domSelect.hide();285 }286 }else if(this.getMode()=='tree'){287 //todo288 }else if(this.getMode()=='grid'){289 //todo290291 if(this._grid!=null){292 this._grid.remove(true);293 this._grid = null;294 }295 if(this.getSelectExt()==true){296 var data = {"title":null,"checkbox":true,"columns":[297 {"bindDataField":"JBXX.zgh","width":"120","colNo":0,"name":"","caption":"èå·¥å·","sortable":true,"align":"center","bold":"true","underline":"true","bgColor":"#efefef","font":"å®ä½","fontSize":"max","fontColor":"black","style":"","adjustContent":"true","format":{"param":"short","functionName":null},"display":false,"type":"integer","visbleType":"text","selectPattern":null,"required":false,"verifyFunctionName":null,"verifyErrorInfo":""},{"bindDataField":"JBXX.xm","width":"70","colNo":1,"name":"","caption":"å§å","sortable":true,"align":"center","bold":"true","underline":"true","bgColor":"#efefef","font":"å®ä½","fontSize":"max","fontColor":"black","style":"","adjustContent":"true","format":{"param":"short","functionName":null},"display":false,"type":"","visbleType":"text","selectPattern":null,"required":false,"verifyFunctionName":null,"verifyErrorInfo":""},{"bindDataField":"JBXX.xb","width":"70","colNo":2,"name":"","caption":"æ§å«","sortable":true,"align":"center","bold":"true","underline":"true","bgColor":"#efefef","font":"å®ä½","fontSize":"max","fontColor":"black","style":"","adjustContent":"true","format":{"param":"short","functionName":null},"display":false,"type":"","visbleType":"text","selectPattern":null,"required":false,"verifyFunctionName":null,"verifyErrorInfo":""}],"data":[{"data":{"JBXX.zgh":{"value":"11","status":"NotModified"},"JBXX.xm":{"value":"å¼ ä¸","status":"NotModified"},"JBXX.xb":{"value":"2","status":"NotModified"}},"status":"NotModified","childData":{}},{"data":{"JBXX.zgh":{"value":"12","status":"NotModified"},"JBXX.xm":{"value":"æå","status":"NotModified"},"JBXX.xb":{"value":"2","status":"NotModified"}},"status":"NotModified","childData":{}},{"data":{"JBXX.zgh":{"value":"232957F7C7A3436880F8A0FE77E24E24","status":"NotModified"},"JBXX.xm":{"value":"æµè¯å¾","status":"NotModified"},"JBXX.xb":{"value":"1","status":"NotModified"}},"status":"NotModified","childData":{}},{"data":{"JBXX.zgh":{"value":"CDB8D1A4122E4F2EBFB91FBCC16AB190","status":"NotModified"},"JBXX.xm":{"value":"æåä¸","status":"NotModified"},"JBXX.xb":{"value":"2","status":"NotModified"}},"status":"NotModified","childData":{}}],"useClientPage":true,"width":210,"height":200,"isScroll":false,"enabledEdit":true,"dblClickToEdit":true,"pageSize":10,"page":1,"refData":{},"total":4};298 var grid = wis$.create('Grid');299 grid.setOptions(data);300 grid.onSelectRow(function(data){console.log(JSON.stringify(data));});301 grid.onCheckRow(function(data){console.log(JSON.stringify(data));});302 grid.setWidth(300);303 var point = this._getPoint(this.getDomInstance().get(0));304 grid.setLeft(point.left);305 grid.setTop(point.top+(this._input.height()+10));306 grid.appendTo(jQuery('body'));307 grid.render();308 this._grid = grid;309 }310311 }312 },313314 // 渲ææ¹æ³315 render: function () {316 //this._comboBox.selectValue(this._value);317318 },319320 // 渲æåå¤çæ¹æ³321 _afterRender: function () {322 this._renderFlag = false;323324 },325326 // ----------å¿
é¡»å®ç°----------327 getData: function () {328 return {329 name: this.getName(),330 selectExt: this.getSelectExt(),331 values: this.getValues(),332 split: this.getSplit(),333 comboBoxName: this.getComboBoxName(),334 isMultiSelect: this.getIsMultiSelect(),335 mode: this.getMode(),336 selectData: this.getSelectData(),337 gridColumn: this.getGridColumn(),338 treeData: this.getTreeData(),339 readonly: this.getReadonly()340 };341 },342343 // ----------å¿
é¡»å®ç°----------344 setData: function (data) {345 this.setName(name);346 this.setSelectExt(data.selectExt);347 this.setValues(data.values);348 this.setSplit(data.split);349 this.setSelectData(data.comboBoxName);350 this.setIsMultiSelect(data.isMultiSelect);351 this.setMode(data.mode);352 this.setSelectData(data.selectData);353 this.setGridColumn(data.gridColumn);354 this.setTreeData(data.treeData);355 this.setReadonly(data.readonly)356 },357358 onBeforeSelect: function (callback) {359 this._onBeforeSelect = callback;360 },361362 onSelected:function(callback){363 this._onSelected = callback;364 },365366 //æ°ç»å»é367 _arrayUnique: function(arr){368 var res = [];369 var json = {};370 for(var i = 0; arr!=null&&i < arr.length; i++){371 if(!json[arr[i]]){372 res.push(arr[i]);373 json[arr[i]] = 1;374 }375 }376 return res;377 },378379 /**380 * è·å¾éä¸ææ¬381 */382 getTexts: function(){383 var texts = [];384 if(this.getMode()=='normal' || this.getMode()=='grid'){385 var data = this.getSelectData();386 var len = data.length;387 for(var i=0;i<len;i++){388 var item = data[i];389 if(jQuery.inArray(item['value'],this.getValues())>-1){390 texts.push(item['name']);391 }392 }393 }else if(this.getMode()=='tree'){394 //todo395 }396 return texts.join(this.getSplit());397 },398399 //è·å¾å¯¹è±¡ç¸å¯¹äºbodyçä½ç½®400 _getPoint: function(obj) {401 var t = obj.offsetTop || 0;402 var l = obj.offsetLeft || 0;403 while (obj = obj.offsetParent) {404 t += obj.offsetTop || 0;405 l += obj.offsetLeft || 0;406 }407 return {top:t,left:l};408 }409
...
function.js
Source:function.js
...22{23 //æ°æ®æéæ§å¤æ24 if (validateSubmit(formId)) {25 // åè½åç§°æ ¡éª 26 var checkName = verifyFunctionName(parameterName,token);27 28 if(checkName){29 //ä¿å30 var url = Utils.getRootPath() +'/function/saveFunction';31 $.ajax({32 type: "POST",33 url: url,34 data:$('#'+formId).serialize(),35 async: false,36 dataType: 'json',37 error: function(request) {38 $.messager.alert('æ示','ç³»ç»å¼å¸¸,请ç¨åéæ°åè¯!','error');39 },40 success: function(result) 41 {42 var message = "";43 var id = $("#id").val();44 if(id != null && id != undefined && id != ''){45 message = "æ´æ°";46 }else{47 message = "ä¿å";48 }49 50 if (null != result && result.status == "OK"){51 $.messager.alert('æ示',message + 'æå','info',function(){52 loadDataGrid("function");53 window.parent.closeWinForm();54 });55 } else{56 $.messager.alert('æ示',message + '失败','error');57 }58 }59 });60 }61 }62}63/**64 * ç¼è¾65 */66function edit(){67 var rows = $('#dg').datagrid('getSelections');68 if(rows.length==0)69 {70 $.messager.alert('æ示','请éæ©éè¦æä½çæ°æ®ï¼','warning');71 return;72 }73 if(rows.length>1)74 {75 $.messager.alert('æ示','请éæ©ä¸æ¡æ°æ®è¿è¡æä½ï¼','warning');76 return;77 }78 var id = rows[0].id;79 add(Utils.getRootPath()+'/function/editFunction?function.id='+id,'ç¼è¾åè½',850,500); 80};81 82/**83 * å é¤84 */85function del(parameterName,token){86 87 var rows = $('#dg').datagrid('getSelections');88 if (rows.length == 0) {89 $.messager.alert('æ示', '请éæ©éè¦æä½çæ°æ®ï¼', 'warning');90 return;91 }92 93 $.messager.confirm('æ示', 'æ¯å¦ç¡®å®å é¤ï¼è¥æä¸çº§åè½ä¸å¹¶å é¤ï¼', function(r) {94 if (r) {95 var str = '';96 for(var i=0; i<rows.length; i++){97 var row = rows[i];98 99 if (str == '') {100 str = row.id;101 } else {102 str += "," + row.id;103 }104 }105 var url = Utils.getRootPath() + '/function/deleteFunction?'+ parameterName + "=" + token;106 $.ajax({107 type : "post",108 url : url,109 data : {110 "functionIds" : str111 },112 async : false,113 dataType : 'json',114 success : function(result) {115 if (result.status == "OK") {116 loadDataGrid("function");117 } else if (result.status == "ERROR") {118 $.messager.alert('æ示', 'å é¤å¤±è´¥', 'error');119 }120 },121 });122 }123 });124}125//éªè¯åè½å称å¯ä¸æ§ 126function verifyFunctionName(parameterName,token)127{128 var checkFlag = false;129 var returnFlag = false;130 // ç¶èç¹id131 var parentId = "";132 //éèåè½å称133 var hiddenFunctionName = $("#hiddenFunctionName").val();134 var functionName = $("#functionName").val();135 functionName = functionName.replace(/(^\s*)|(\s*$)/g, "");136 if ((hiddenFunctionName=='')||(hiddenFunctionName != '' && hiddenFunctionName != functionName)) 137 {138 if(hiddenFunctionName=='' || hiddenFunctionName== undefined){139 parentId = $("#addParentId").val()140 }else{...
Using AI Code Generation
1var assert = require('assert');2var sinon = require('sinon');3var foo = {4 setName: function (name) {5 this.name = name;6 }7};8var setNameSpy = sinon.spy(foo, "setName");9foo.setName("bar");10assert(sinon.assert.calledOn(setNameSpy, foo));11assert(sinon.assert.calledWith(setNameSpy, "bar"));12assert(sinon.assert.calledOnce(setNameSpy));13assert(sinon.assert.called(setNameSpy));14assert(sinon.assert.callCount(setNameSpy, 1));15assert(sinon.assert.alwaysCalledOn(setNameSpy, foo));16assert(sinon.assert.alwaysCalledWith(setNameSpy, "bar"));17assert(sinon.assert.neverCalledWith(setNameSpy, "bar"));18assert(sinon.assert.alwaysCalledWithExactly(setNameSpy, "bar"));19assert(sinon.assert.neverCalledWithExactly(setNameSpy, "bar"));20assert(sinon.assert.calledWithNew(setNameSpy));21assert(sinon.assert.calledWithMatch(setNameSpy, "bar"));22assert(sinon.assert.alwaysCalledWithMatch(setNameSpy, "bar"));23assert(sinon.assert.neverCalledWithMatch(setNameSpy, "bar"));24assert(sinon.assert.calledWithExactly(setNameSpy, "bar"));25assert(sinon.assert.neverCalledWithExactly(setNameSpy, "bar"));26assert(sinon.assert.calledBefore(setNameSpy, setNameSpy));27assert(sinon.assert.calledAfter(setNameSpy, setNameSpy));28assert(sinon.assert.calledImmediatelyBefore(setNameSpy, setNameSpy));29assert(sinon.assert.calledImmediatelyAfter(setNameSpy, setNameSpy));30assert(sinon.assert.calledOn(setNameSpy, foo));31assert(sinon.assert.alwaysCalledOn(setNameSpy, foo));32assert(sinon.assert.calledWith(setNameSpy, "bar"));33assert(sinon.assert.alwaysCalledWith(setNameSpy, "bar"));34assert(sinon.assert.neverCalledWith(setNameSpy, "bar"));35assert(sinon.assert.calledWithExactly(setNameSpy, "bar"));36assert(sinon.assert.alwaysCalledWithExactly(setNameSpy, "bar"));37assert(sinon.assert.neverCalledWithExactly(setNameSpy, "bar"));38assert(sinon.assert.calledWithMatch(setNameSpy, "bar"));39assert(sinon.assert.alwaysCalledWithMatch(setNameSpy, "bar"));40assert(sinon.assert.neverCalledWithMatch(setNameSpy, "bar"));41assert(sinon.assert.calledWithNew(setNameSpy));
Using AI Code Generation
1var sinon = require('sinon');2var assert = require('assert');3var foo = { method: function() {} };4var bar = { method: function() {} };5sinon.spy(foo, "method");6sinon.spy(bar, "method");7foo.method(42);8bar.method(1);9assert(foo.method.calledOn(foo));10assert(bar.method.calledOn(bar));11var sinon = require('sinon');12var assert = require('assert');13var foo = { method: function() {} };14var bar = { method: function() {} };15sinon.spy(foo, "method");16sinon.spy(bar, "method");17foo.method(42);18bar.method(1);19assert(foo.method.calledOn(foo));20assert(bar.method.calledOn(bar));21var sinon = require('sinon');22var assert = require('assert');23var foo = { method: function() {} };24var bar = { method: function() {} };25sinon.spy(foo, "method");26sinon.spy(bar, "method");27foo.method(42);28bar.method(1);29assert(foo.method.calledOn(foo));30assert(bar.method.calledOn(bar));31var sinon = require('sinon');32var assert = require('assert');33var foo = { method: function() {} };34var bar = { method: function() {} };35sinon.spy(foo, "method");36sinon.spy(bar, "method");37foo.method(42);38bar.method(1);39assert(foo.method.calledOn(foo));40assert(bar.method.calledOn(bar));41var sinon = require('sinon');42var assert = require('assert');43var foo = { method: function() {} };44var bar = { method: function() {} };45sinon.spy(foo, "method");46sinon.spy(bar, "method");47foo.method(42);48bar.method(1);49assert(foo.method.calledOn(foo));50assert(bar.method.calledOn(bar));51var sinon = require('sinon');52var assert = require('assert');53var foo = { method: function() {} };54var bar = { method: function() {} };55sinon.spy(foo, "method");56sinon.spy(bar, "method");57foo.method(42);58bar.method(1);59assert(foo.method.calledOn(foo));
Using AI Code Generation
1var sinon = require('sinon');2var assert = require('assert');3var myObj = {4 myFunc: function() {5 console.log('myFunc called');6 }7};8var spy = sinon.spy(myObj, 'myFunc');9myObj.myFunc();10assert(spy.called);11assert(myObj.myFunc.verifyFunctionName('myFunc'));12assert(myObj.myFunc.verifyFunctionName('myFunc2') === false);
Using AI Code Generation
1var assert = require('assert');2var sinon = require('sinon');3var obj = {4 method: function () {}5};6var spy = sinon.spy(obj, 'method');7assert.ok(sinon.assert.verifyFunctionName(spy, 'method'));8var assert = require('assert');9var sinon = require('sinon');10var obj = {11 method: function () {}12};13var spy = sinon.spy(obj, 'method');14assert.ok(sinon.assert.verifyFunctionName(spy, 'method'));15var assert = require('assert');16var sinon = require('sinon');17var obj = {18 method: function () {}19};20var spy = sinon.spy(obj, 'method');21assert.ok(sinon.assert.verifyFunctionName(spy, 'method'));22var assert = require('assert');23var sinon = require('sinon');24var obj = {25 method: function () {}26};27var spy = sinon.spy(obj, 'method');28assert.ok(sinon.assert.verifyFunctionName(spy, 'method'));29var assert = require('assert');30var sinon = require('sinon');31var obj = {32 method: function () {}33};34var spy = sinon.spy(obj, 'method');35assert.ok(sinon.assert.verifyFunctionName(spy, 'method'));36var assert = require('assert');37var sinon = require('sinon');38var obj = {39 method: function () {}40};41var spy = sinon.spy(obj, 'method');42assert.ok(sinon.assert.verifyFunctionName(spy, 'method'));
Using AI Code Generation
1var sinon = require('sinon');2var myObj = {3 myMethod: function () {}4};5var spy = sinon.spy(myObj, 'myMethod');6myObj.myMethod();7console.log(spy.called);8var sinon = require('sinon');9var myObj = {10 myMethod: function () {}11};12var spy = sinon.spy(myObj, 'myMethod');13myObj.myMethod();14console.log(spy.called);15var sinon = require('sinon');16var myObj = {17 myMethod: function () {}18};19var spy = sinon.spy(myObj, 'myMethod');20myObj.myMethod();21console.log(spy.called);22var sinon = require('sinon');23var myObj = {24 myMethod: function () {}25};26var spy = sinon.spy(myObj, 'myMethod');27myObj.myMethod();28console.log(spy.called);29var sinon = require('sinon');30var myObj = {31 myMethod: function () {}32};33var spy = sinon.spy(myObj, 'myMethod');34myObj.myMethod();35console.log(spy.called);36var sinon = require('sinon');37var myObj = {38 myMethod: function () {}39};40var spy = sinon.spy(myObj, 'myMethod');41myObj.myMethod();42console.log(spy.called);43var sinon = require('sinon');44var myObj = {45 myMethod: function () {}46};47var spy = sinon.spy(myObj, 'myMethod');48myObj.myMethod();49console.log(spy.called);50var sinon = require('sinon');51var myObj = {52 myMethod: function () {}53};54var spy = sinon.spy(myObj, 'myMethod');55myObj.myMethod();56console.log(spy.called);57var sinon = require('sinon');58var myObj = {59 myMethod: function ()
Using AI Code Generation
1var sinon = require('sinon');2var assert = require('assert');3function myFunction(){}4var spy = sinon.spy(myFunction);5spy();6assert(spy.calledOnce);7assert(spy.calledWith());8assert(spy.withArgs().calledOnce);9assert(spy.calledOn(myFunction));10assert(spy.calledWithExactly());11assert(spy.withArgs().calledOnce);12assert(spy.calledOn(myFunction));13assert(spy.calledWithMatch());14assert(spy.withArgs().calledOnce);15assert(spy.calledOn(myFunction));16assert(spy.calledWithNew());17assert(spy.withArgs().calledOnce);18assert(spy.calledOn(myFunction));19assert(spy.calledWithExactlyNew());20assert(spy.withArgs().calledOnce);21assert(spy.calledOn(myFunction));22assert(spy.calledWithMatchNew());23assert(spy.withArgs().calledOnce);24assert(spy.calledOn(myFunction));25assert(spy.calledWithNew(myFunction));26assert(spy.withArgs().calledOnce);27assert(spy.calledOn(myFunction));28assert(spy.calledWithExactlyNew(myFunction));29assert(spy.withArgs().calledOnce);30assert(spy.calledOn(myFunction));31assert(spy.calledWithMatchNew(myFunction));32assert(spy.withArgs().calledOnce);33assert(spy.calledOn(myFunction));34assert(spy.calledWithNew(myFunction, 1, 2));35assert(spy.withArgs().calledOnce);36assert(spy.calledOn(myFunction));37assert(spy.calledWithExactlyNew(myFunction, 1, 2));38assert(spy.withArgs().calledOnce);39assert(spy.calledOn(myFunction));40assert(spy.calledWithMatchNew(myFunction, 1, 2));41assert(spy.withArgs().calledOnce);42assert(spy.calledOn(myFunction));43assert(spy.calledWithNew(myFunction, 1, 2, 3));44assert(spy.withArgs().calledOnce);45assert(spy.calledOn(myFunction));46assert(spy.calledWithExactlyNew(myFunction, 1, 2, 3));47assert(spy.withArgs().calledOnce);48assert(spy.calledOn(myFunction));49assert(spy.calledWithMatchNew(myFunction, 1, 2, 3));50assert(spy.withArgs().calledOnce);51assert(spy.calledOn(myFunction));52assert(spy.calledWithNew(myFunction, 1, 2, 3, 4));53assert(spy.withArgs().calledOnce);54assert(spy
Using AI Code Generation
1var sinon = require('sinon');2var myObj = {3 myFunc: function() {}4};5sinon.assert.verifyFunctionName(myObj.myFunc, 'myFunc');6var chai = require('chai');7var assert = chai.assert;8var myObj = {9 myFunc: function() {}10};11assert.verifyFunctionName(myObj.myFunc, 'myFunc');12var chai = require('chai');13var assert = chai.assert;14var myObj = {15 myFunc: function() {}16};17assert.isFunction(myObj.myFunc, 'myFunc');
Using AI Code Generation
1var sinon = require('sinon');2var assert = require('assert');3var testFunction = function () {4 console.log('this is a test function');5}6var spy = sinon.spy(testFunction);7spy();8assert.equal(sinon.spyCall.toString(), 'this is a test function');9var sinon = require('sinon');10var assert = require('assert');11var testFunction = function () {12 console.log('this is a test function');13}14var spy = sinon.spy(testFunction);15spy();16assert.equal(sinon.spyCall.returnValue, undefined);17var sinon = require('sinon');18var assert = require('assert');19var testFunction = function () {20 console.log('this is a test function');21}22var spy = sinon.spy(testFunction);23spy();24assert.equal(sinon.spyCall.callCount, 1);25var sinon = require('sinon');26var assert = require('assert');27var testFunction = function () {28 console.log('this is a test function');29}30var spy = sinon.spy(testFunction);
Using AI Code Generation
1var sinon = require('sinon');2var stub = sinon.stub();3stub.verifyFunctionName('test');4var sinon = require('sinon');5var stub = sinon.stub();6stub.restore();7var sinon = require('sinon');8var stub = sinon.stub();9stub.log('test');10var sinon = require('sinon');11var stub = sinon.stub();12stub.logError('test');13var sinon = require('sinon');14var stub = sinon.stub();15stub.createStubInstance('test');16var sinon = require('sinon');17var stub = sinon.stub();18stub.match('test');19var sinon = require('sinon');20var stub = sinon.stub();21stub.createStubInstance('test');22var sinon = require('sinon');23var stub = sinon.stub();24stub.createStubInstance('test');25var sinon = require('sinon');26var stub = sinon.stub();27stub.createStubInstance('test');28var sinon = require('sinon');29var stub = sinon.stub();30stub.createStubInstance('test');31var sinon = require('sinon');32var stub = sinon.stub();33stub.createStubInstance('test');34var sinon = require('sinon');35var stub = sinon.stub();36stub.createStubInstance('test');37var sinon = require('sinon');38var stub = sinon.stub();39stub.createStubInstance('test');40var sinon = require('sinon');41var stub = sinon.stub();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!