Best JavaScript code snippet using sinon
siteDesigner.js
Source:siteDesigner.js  
1var style_data = new Object();2var style_data_JSON = '';3/* Init colorpicker */4	$(document).ready(function() {5	6		$.farbtastic('#colorpicker', function callback(color) {7											changeStyle(color);							8										   });9		$("#layout_file").uploadify({10			'uploader'       : '/flash/uploadify.swf',11			'script'         : '/upload',12			'cancelImg'      : '/images/cancel.png',13			'buttonImg'      : '/images/browse-files.png',14			'wmode'          : 'transparent',15			'width'          : 98,16			'queueID'        : 'fileQueue',17			'auto'           : true,18			'multi'          : false,19			'fileDataName'   : 'fileData',20			'fileDesc'		 : 'Image Files',21			'fileExt'		 : '*.gif;*.jpg;*.png;*.tif;*.tiff',22			'onComplete'  	 : function(event, queueID, fileObj, response, data){23							24								cleanResponse = trim(response);25								uploadResponse(cleanResponse);26								27							},28			'scriptData'	 :	{29									directory:directory,30									communityID: communityid, 31									fkType:'layout',32									procFile: 'util.upload.layout'33								}34		});    					   35	});36	/* setup selectbox click handlers */37	$("#myitem, #myelement, #myproperty").bind("click", function(e){38		changeControls();39	});40	$('#currentValue').bind('keyup', function(event, ui){41		changeStyle($('#currentValue').val());										  42    });43	$('#sizeSlider').bind('slide', function(event, ui) {44		var value1 = $('#sizeSlider').slider('option', 'value');45		var value2 = $('#sizeSliderFine').slider('option', 'value');46		var value = value1 + value2;47		changeStyle(value+'px');48	});49	50	$('#sizeSliderFine').bind('slide', function(event, ui) {51		var value1 = $('#sizeSlider').slider('option', 'value');52		var value2 = $('#sizeSliderFine').slider('option', 'value');53		var value = value1 + value2;54		changeStyle(value+'px');55	});56	$('#fontFamily').bind('change', function(event,ui){ 57		value = $('#fontFamily').val();58		changeStyle(value, 'fontFamily'); 59	});60	$('#fontSize').bind('change', function(event,ui){ 61		value = $('#fontSize').val();62		changeStyle(value, 'fontSize');63	});64	$('#fontWeight').bind('change', function(event,ui){ 65		value = $('#fontWeight').val();66		changeStyle(value, 'fontWeight');67	});68	$('#fontStyle').bind('change', function(event,ui){ 69		value = $('#fontStyle').val();70		changeStyle(value, 'fontStyle');71	});72	73	$('#textAlignment').bind('change', function(event,ui){ 74		value = $('#textAlignment').val();75		changeStyle(value, 'textAlign');76	});77	$('#textDecoration').bind('change', function(event,ui){ 78		value = $('#textDecoration').val();79		changeStyle(value, 'textDecoration');80	});81	$('#textDisplay').bind('change', function(event,ui){ 82		value = $('#textDisplay').val();83		changeStyle(value, 'display');84	});85	$('#backgroundPosition').bind('change', function(event,ui){ 86		value = $('#backgroundPosition').val();87		changeStyle(value, 'backgroundPosition');88	});89	90	$('#backgroundRepeat').bind('change', function(event,ui){ 91		value = $('#backgroundRepeat').val();92		changeStyle(value, 'backgroundRepeat');93	});94	$('#paddingTop').bind('slide', function(event,ui){ 95		var elCombo = $('#myproperty').val(); 96		var elArray = elCombo.split("!");97		var myProperty = elArray[1];	98		var value = $('#paddingTop').slider('option', 'value') + 'px '+$('#paddingRight').slider('option', 'value') + 'px '+$('#paddingBottom').slider('option', 'value') + 'px '+$('#paddingLeft').slider('option', 'value') + 'px ';99		changeStyle(value,myProperty);100		101		$('#currentValue').val(value);102	});103	$('#paddingRight').bind('slide', function(event,ui){ 104		var elCombo = $('#myproperty').val(); 105		var elArray = elCombo.split("!");106		var myProperty = elArray[1];	107			var value = $('#paddingTop').slider('option', 'value') + 'px '+$('#paddingRight').slider('option', 'value') + 'px '+$('#paddingBottom').slider('option', 'value') + 'px '+$('#paddingLeft').slider('option', 'value') + 'px ';108		changeStyle(value,myProperty);109		110		$('#currentValue').val(value);111	});112	$('#paddingBottom').bind('slide', function(event,ui){ 113		var elCombo = $('#myproperty').val(); 114		var elArray = elCombo.split("!");115		var myProperty = elArray[1];	116				var value = $('#paddingTop').slider('option', 'value') + 'px '+$('#paddingRight').slider('option', 'value') + 'px '+$('#paddingBottom').slider('option', 'value') + 'px '+$('#paddingLeft').slider('option', 'value') + 'px ';117		changeStyle(value,myProperty);118		119		$('#currentValue').val(value);120	});121	$('#paddingLeft').bind('slide', function(event,ui){ 122		var elCombo = $('#myproperty').val(); 123		var elArray = elCombo.split("!");124		var myProperty = elArray[1];	125		var value = $('#paddingTop').slider('option', 'value') + 'px '+$('#paddingRight').slider('option', 'value') + 'px '+$('#paddingBottom').slider('option', 'value') + 'px '+$('#paddingLeft').slider('option', 'value') + 'px ';126		changeStyle(value,myProperty);127		128		$('#currentValue').val(value);129	});130$('#marginTop').bind('slide', function(event,ui){ 131		var elCombo = $('#myproperty').val(); 132		var elArray = elCombo.split("!");133		var myProperty = elArray[1];	134		var value = $('#marginTop').slider('option', 'value') + 'px '+$('#marginRight').slider('option', 'value') + 'px '+$('#marginBottom').slider('option', 'value') + 'px '+$('#marginLeft').slider('option', 'value') + 'px ';135		changeStyle(value,myProperty);136		137		$('#currentValue').val(value);138	});139	$('#marginRight').bind('slide', function(event,ui){ 140		var elCombo = $('#myproperty').val(); 141		var elArray = elCombo.split("!");142		var myProperty = elArray[1];	143			var value = $('#marginTop').slider('option', 'value') + 'px '+$('#marginRight').slider('option', 'value') + 'px '+$('#marginBottom').slider('option', 'value') + 'px '+$('#marginLeft').slider('option', 'value') + 'px ';144		changeStyle(value,myProperty);145		146		$('#currentValue').val(value);147	});148	$('#marginBottom').bind('slide', function(event,ui){ 149		var elCombo = $('#myproperty').val(); 150		var elArray = elCombo.split("!");151		var myProperty = elArray[1];	152			var value = $('#marginTop').slider('option', 'value') + 'px '+$('#marginRight').slider('option', 'value') + 'px '+$('#marginBottom').slider('option', 'value') + 'px '+$('#marginLeft').slider('option', 'value') + 'px ';153		changeStyle(value,myProperty);154		155		$('#currentValue').val(value);156	});157	$('#marginLeft').bind('slide', function(event,ui){ 158		var elCombo = $('#myproperty').val(); 159		var elArray = elCombo.split("!");160		var myProperty = elArray[1];	161var value = $('#marginTop').slider('option', 'value') + 'px '+$('#marginRight').slider('option', 'value') + 'px '+$('#marginBottom').slider('option', 'value') + 'px '+$('#marginLeft').slider('option', 'value') + 'px ';162		changeStyle(value,myProperty);163		164		$('#currentValue').val(value);165	});166	function changeControls(){167	var elCombo = $('#myproperty').val(); 168		var elArray = elCombo.split("!");169		var myEl = elArray[0];	170		$('#mystyle').html(myEl);171		172	   		var myProperty = $('#myproperty').val();173			var myValue = getMyStyle();174			if (myProperty.indexOf('olor') > -1){ 175				if ($('#colorpicker').is(':hidden')){ 176					hideAllControls();177					$('#colorpicker').show();178				}179				myValue=rgb2hex(myValue);180				$.farbtastic('#colorpicker').setColor(myValue);				181			}182			183			if (myProperty.indexOf('eight') > -1 || myProperty.indexOf('idth') > -1){ 184				if ($('#slider').is(':hidden')){ 185					hideAllControls();186					$('#slider').show();187				}188				189				$('#currentValue').val(myValue);190				myValue = myValue.replace(/px,*\)*/g,"");191				192				coarseValue = Math.round(myValue/10);193				fineValue = Math.round(myValue-coarseValue);194				195				$("#sizeSlider").slider({ value: coarseValue, min: 0, max: 1000, step: 10});196				$("#sizeSliderFine").slider({ value: fineValue, min: 0, max: 10, step: 1});197			}198			199			if (myProperty.indexOf('adding') > -1 ){ 200				201			202				paddingValue = getPadding();203				$('#currentValue').val(paddingValue);204		205				if ($('#padding').is(':hidden')){ 206					hideAllControls();207					$('#padding').show();208				}209				210				$("#paddingTop").slider({ value: topValue, min: 0, max: 500, step: 2, orientation: 'horizontal'});211				$("#paddingRight").slider({ value: rightValue, min: 0, max: 500, step: 2, orientation: 'horizontal'});212				$("#paddingBottom").slider({ value: bottomValue, min: 0, max: 500, step: 2, orientation: 'horizontal'});213				$("#paddingLeft").slider({ value: leftValue, min: 0, max: 500, step: 2, orientation: 'horizontal'});214				215			}216			217		if (myProperty.indexOf('argin') > -1 ){ 218				219			220				marginValue = getMargin();221				$('#currentValue').val(marginValue);222		223				if ($('#margin').is(':hidden')){ 224					hideAllControls();225					$('#margin').show();226				}227				228				$("#marginTop").slider({ value: topValue, min: 0, max: 500, step: 2, orientation: 'horizontal'});229				$("#marginRight").slider({ value: rightValue, min: 0, max: 500, step: 2, orientation: 'horizontal'});230				$("#marginBottom").slider({ value: bottomValue, min: 0, max: 500, step: 2, orientation: 'horizontal'});231				$("#marginLeft").slider({ value: leftValue, min: 0, max: 500, step: 2, orientation: 'horizontal'});232				233			}234			if (myProperty.indexOf('Image') > -1){ 235				var elCombo = $('#myproperty').val(); 236				var elArray = elCombo.split("!");237				var myEl = elArray[0];238				var myProperty = elArray[1];239		240				formField = myEl & '_' & myProperty;	241				242				if ($('#uploader').is(':hidden')){ 243					hideAllControls();244					$('#uploader').show();245				}246			}247			248			if (myProperty.indexOf('font') > -1){ 249				if ($('#text').is(':hidden')){ 250					hideAllControls();251					$('#text').show();252				}253				254				$('#fontFamily').val(getMyStyle('fontFamily'));255				$('#fontSize').val(getMyStyle('fontSize'));256				$('#fontWeight').val(getMyStyle('fontWeight'));257				$('#fontStyle').val(getMyStyle('fontStyle'));258				259				$('#textAlignment').val(getMyStyle('textAlign'));260				$('#textDecoration').val(getMyStyle('textDecoration'));261				$('#textDisplay').val(getMyStyle('display'));262				if($('#myelement').val() == '#ft'){ 263					$('#textDisplay').hide();264					$('#textAlignment').hide();265				} else { 266				$('#textDisplay').show();267					$('#textAlignment').show();268				}269			} 270			271	}272	/* hide all ui control divs */ 273	function hideAllControls(){274		$('#colorpicker').hide();275		$('#uploader').hide();276		$('#text').hide();277		$('#slider').hide();278		$('#padding').hide();279		$('#margin').hide();280	}281	/* change the style! */282	function changeStyle(value, property){283	284		var elCombo = $('#myproperty').val(); 285		var elArray = elCombo.split("!");286		var myEl = elArray[0];	287		if (property == undefined){288			var myProperty = elArray[1];289		} else { 290			var myProperty=property;291		}292		/* Update CSS */ 293		$(myEl).css(myProperty, value);294		295		/* Update Form Field */296		$('#currentValue').val(value);297	298		// Loop the myEL as a list..  use the index of the list and myproperty / value 299var valueArray = myEl.split(",");300for(var i=0; i<valueArray.length; i++){301 302	 	var new_data = '{"' + valueArray[i] +'" : {"' + myProperty +  '" : "'+value+'"}}';303	// TODO: remove YUI3..  this is prob the only reason its still around.. jquery now has these sorts of functions304		YUI({combine: true, timeout: 10000}).use("node", "io", "dump", "json-parse",function (Y) { 305			YUI().use('json', function(Y) {    306	   			thisData = Y.JSON.parse('{"'+myProperty+'":"'+value+'"}');307				   style_data[valueArray[i]] = Y.merge(style_data[valueArray[i] ], thisData) ;308				   style_data_JSON = Y.JSON.stringify(style_data);309			});310		});311}312	}313	/* Retrieve a style */ 314	function getMyStyle( property ){315			var elCombo = $('#myproperty').val(); 316			var elArray = elCombo.split("!");317			var myEl = elArray[0];318			if(property == undefined){319				var myProperty = elArray[1];320			} else { 321				var myProperty = property;322			}323        	var	style = $(myEl).css(myProperty);324			325			return style;326	}327function getPadding(){328			var elCombo = $('#myproperty').val(); 329			var elArray = elCombo.split("!");330			var myProperty = elArray[1];331			topVal = getMyStyle(myProperty + 'Top');332				topValue = topVal.replace(/px,*\)*/g,"");333				rightVal = getMyStyle(myProperty + 'Right');334				rightValue = rightVal.replace(/px,*\)*/g,"");335				bottomVal = getMyStyle(myProperty + 'Bottom');336				bottomValue = bottomVal.replace(/px,*\)*/g,"");337				leftVal = getMyStyle(myProperty + 'Left') ;338				leftValue = leftVal.replace(/px,*\)*/g,"");339				paddingValue = topVal + ' ' + rightVal + ' ' + bottomVal + ' ' + leftVal;340				return paddingValue;341}342function getMargin(){343			var elCombo = $('#myproperty').val(); 344			var elArray = elCombo.split("!");345			var myProperty = elArray[1];346			topVal = getMyStyle(myProperty + 'Top');347				topValue = topVal.replace(/px,*\)*/g,"");348				rightVal = getMyStyle(myProperty + 'Right');349				rightValue = rightVal.replace(/px,*\)*/g,"");350				bottomVal = getMyStyle(myProperty + 'Bottom');351				bottomValue = bottomVal.replace(/px,*\)*/g,"");352				leftVal = getMyStyle(myProperty + 'Left') ;353				leftValue = leftVal.replace(/px,*\)*/g,"");354				marginValue = topVal + ' ' + rightVal + ' ' + bottomVal + ' ' + leftVal;355				return marginValue;356}357	358	359function fill_dependentStyle(field1, field2, url){360	var cid = $('#'+field1).val();						361	var mytext = $('#'+field1 + ' option:selected').text();						362	cid = escape(cid);363	mytext = escape(mytext);364	var vURL =url + cid + '/text/' + mytext;365	var handleSuccess = function(o){366		/* Rebuild the select boxes */367		var objElmt = document.getElementById(field2);368		var objResponse = request.responseText;369		var trimmed = objResponse.replace(/^\s+|\s+$/g, '') ;370		var objArray = trimmed.split("|");371		objElmt.length = objArray.length ;372		var cnt = 0;373		if(trimmed == ''){374			objElmt.length = 0 ;375			objElmt[0].value = '';376			objElmt[0].text =  '';	377		} else{378			for (o = 0; o < objArray.length; o++){   		379				var objIdValue = objArray[o].split("~");380				objValue = objIdValue[0];381				objText = objIdValue[1];382				objElmt[cnt].value = objValue;383				objElmt[cnt].text =  objText;	384				cnt++;385			}386			objElmt.selectedIndex = 0;387		}	388		if (field1 == 'myitem'){389			updateStyleSelect2();390		}391}392	var request = $.ajax({393						 	url: vURL, 394						 	success: handleSuccess395						 });396}397function updateStyleSelect1(){398	fill_dependentStyle('myitem', 'myelement', '/index.cfm/cms/style/elements/itemID/');399}400function updateStyleSelect2(){401	fill_dependentStyle('myelement', 'myproperty', '/index.cfm/cms/style/properties/element/');402}403function rgb2hex(rgbString) {404	//generates the hex-digits for a colour.405var parts = rgbString406        .match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/)407;408// parts now should be ["rgb(0, 70, 255", "0", "70", "255"]409delete (parts[0]);410for (var i = 1; i <= 3; ++i) {411    parts[i] = parseInt(parts[i]).toString(16);412    if (parts[i].length == 1) parts[i] = '0' + parts[i];413}414var hexString = parts.join(''); // "0070ff"415return '#' + hexString;416} 417		function trim(str, chars) {418		    return ltrim(rtrim(str, chars), chars);419		}420		421		function ltrim(str, chars) {422		    chars = chars || "\\s";423		    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");424		}425		426		function rtrim(str, chars) {427		    chars = chars || "\\s";428		    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");429		}430		431	432	433			434		435			fileID = null;436	437	// Do something when data is received back from the server.438	function uploadResponse(response) {439		var responseArray = response.split('|');440		var str = "url("+responseArray[1]+")";441		442		changeStyle(str);443	}444	function resetColor(){445		changeStyle('transparent','backgroundColor');446	}447				448				449	function resetImage(){ 450		changeStyle('url()','backgroundImage');451	}452function saveDesign(){453$.post("/index.cfm/cms/style/save", { 454	data:style_data_JSON,455	templateid: $('#templateID').val(),456	extracss: $('#extraCSS').val(),457	designtype: $('#designtype').val()458	   459	   },460  function(data){461  		location.href=document.getElementById('lastPage').value ;462  });463	464}465/* Do the initial get of the Select boxes */...S15.4.2.1_A1.1_T1.js
Source:S15.4.2.1_A1.1_T1.js  
1// Copyright 2009 the Sputnik authors.  All rights reserved.2// This code is governed by the BSD license found in the LICENSE file.3/*---4info: |5    The [[Prototype]] property of the newly constructed object6    is set to the original Array prototype object, the one that7    is the initial value of Array.prototype8es5id: 15.4.2.1_A1.1_T19description: >10    Create new property of Array.prototype. When new Array object has11    this property12---*/13//CHECK#114Array.prototype.myproperty = 1;15var x = new Array();16if (x.myproperty !== 1) {17  $ERROR('#1: Array.prototype.myproperty = 1; var x = new Array(); x.myproperty === 1. Actual: ' + (x.myproperty));18}19//CHECK#220if (x.hasOwnProperty('myproperty') !== false) {21  $ERROR('#2: Array.prototype.myproperty = 1; var x = new Array(); x.hasOwnProperty(\'myproperty\') === false. Actual: ' + (x.hasOwnProperty('myproperty')));22}...S15.4.3_A1.1_T1.js
Source:S15.4.3_A1.1_T1.js  
1// Copyright 2009 the Sputnik authors.  All rights reserved.2// This code is governed by the BSD license found in the LICENSE file.3/*---4info: |5    The value of the internal [[Prototype]] property of6    the Array constructor is the Function prototype object7es5id: 15.4.3_A1.1_T18description: >9    Create new property of Function.prototype. When Array constructor10    has this property11---*/12Function.prototype.myproperty = 1;13//CHECK#114if (Array.myproperty !== 1) {15  $ERROR('#1: Function.prototype.myproperty = 1; Array.myproperty === 1. Actual: ' + (Array.myproperty));16}17//CHECK#218if (Array.hasOwnProperty('myproperty') !== false) {19  $ERROR('#2: Function.prototype.myproperty = 1; Array.hasOwnProperty(\'myproperty\') === false. Actual: ' + (Array.hasOwnProperty('myproperty')));20}...Using AI Code Generation
1var sinon = require('sinon');2var chai = require('chai');3var expect = chai.expect;4var sinonChai = require('sinon-chai');5chai.use(sinonChai);6var myObject = {7  myMethod: function() {8    return true;9  }10};11describe('myObject', function() {12  it('should have a method called myMethod', function() {13    expect(myObject).to.have.property('myMethod');14  });15  it('should have a method called myMethod that returns true', function() {16    expect(myObject.myMethod()).to.be.true;17  });18  it('should have a method called myMethod that returns true using sinon', function() {19    var spy = sinon.spy(myObject, 'myMethod');20    myObject.myMethod();21    expect(spy).to.have.been.called;22    spy.restore();23  });24});25{26  "scripts": {27  },28  "devDependencies": {29  }30}Using AI Code Generation
1var sinon = require('sinon');2var myObject = {3  myProperty: function() {4    console.log('myProperty called');5  }6};7var spy = sinon.spy(myObject, 'myProperty');8myObject.myProperty();9var sinon = require('sinon');10var myObject = {11  myProperty: function() {12    console.log('myProperty called');13  }14};15var spy = sinon.spy(myObject, 'myProperty');16myObject.myProperty();17var sinon = require('sinon');18var myObject = {19  myProperty: function() {20    console.log('myProperty called');21  }22};23var spy = sinon.spy(myObject, 'myProperty');24myObject.myProperty();25var sinon = require('sinon');26var myObject = {27  myProperty: function() {28    console.log('myProperty called');29  }30};31var spy = sinon.spy(myObject, 'myProperty');32myObject.myProperty();33var sinon = require('sinon');34var myObject = {35  myProperty: function() {36    console.log('myProperty called');37  }38};Using AI Code Generation
1var sinon = require('sinon');2var object = {myProperty: 'value'};3var stub = sinon.stub(object, 'myProperty').returns(42);4var sinon = require('sinon');5var object = {myMethod: function () {return 42;}};6var stub = sinon.stub(object, 'myMethod');7stub.returns(42);8var sinon = require('sinon');9var object = {myMethod: function () {return 42;}};10var stub = sinon.stub(object, 'myMethod').returns(42);11var sinon = require('sinon');12var object = {myMethod: function () {return 42;}};13var stub = sinon.stub(object, 'myMethod');14stub.returns(42);15var sinon = require('sinon');16var object = {myMethod: function () {return 42;}};17var stub = sinon.stub(object, 'myMethod').returns(42);18var sinon = require('sinon');19var object = {myMethod: function () {return 42;}};20var stub = sinon.stub(object, 'myMethod').returns(42);Using AI Code Generation
1sinon.test(function () {2    var myObject = { myProperty: 1 };3    myObject.myProperty = 2;4    this.mock(myObject).expects("myProperty").once().withExactArgs(2);5    myObject.myProperty = 2;6}).restore();7sinon.test(function () {8    var myObject = { myMethod: function () { return 1; } };9    this.stub(myObject, "myMethod").returns(2);10    console.log(myObject.myMethod());11}).restore();12sinon.test(function () {13    var myObject = { myMethod: function () { return 1; } };14    this.spy(myObject, "myMethod");15    myObject.myMethod();16    this.mock(myObject.myMethod).verify();17}).restore();18sinon.test(function () {19    var clock = this.useFakeTimers();20    clock.tick(100);21}).restore();22sinon.test(function () {23    var server = this.useFakeServer();24    server.respondWith("GET", "/resource", [200, { "Content-Type": "text/plain" }, "response"]);25    server.respond();26}).restore();27sinon.test(function () {28    var xhr = this.useFakeXMLHttpRequest();29    xhr.onCreate = function (xhr) {30    };31}).restore();32sinon.test(function () {33    var server = this.useFakeServer();34    server.autoRespond = true;35    server.respondWith(function (xhr) {36        xhr.respond(200, { "Content-Type": "text/plain" }, "response");37    });38}).restore();Using AI Code Generation
1var assert = require("assert");2var sinon = require("sinon");3describe("sinon spy", function() {4  it("should return the value of the property", function() {5    var spy = sinon.spy();6    spy("hello");7    spy.myProperty = "world";8    assert.equal(spy.myProperty, "world");9  });10  it("should return the value of the property", function() {11    var spy = sinon.spy();12    spy("hello");13    spy.myProperty = "world";14    assert.equal(spy.myProperty, "world");15  });16  it("should return the value of the property", function() {17    var spy = sinon.spy();18    spy("hello");19    spy.myProperty = "world";20    assert.equal(spy.myProperty, "world");21  });22  it("should return the value of the property", function() {23    var spy = sinon.spy();24    spy("hello");25    spy.myProperty = "world";26    assert.equal(spy.myProperty, "world");27  });28});29var assert = require("assert");30var sinon = require("sinon");31describe("sinon spy", function() {32  it("should return the value of the property", function() {33    var spy = sinon.spy();34    spy("hello");35    spy.myProperty = "world";36    assert.equal(spy.myUsing AI Code Generation
1var sinon = require('sinon');2function myFunction() {3    return 'myFunction';4}5var spy = sinon.spy(myFunction);6spy();7var sinon = require('sinon');8function myFunction() {9    return 'myFunction';10}11var stub = sinon.stub(myFunction);12stub();13var sinon = require('sinon');14function myFunction() {15    return 'myFunction';16}17var stub = sinon.stub(myFunction);18stub.returns('stubbed');19stub();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!!
