Best JavaScript code snippet using sinon
mDialog.js
Source:mDialog.js  
1;(function (root, factory) {2	if (typeof define === 'function' && define.amd){3		define(['zepto', 'mHistory', 'popup'],factory);4	}else{5		factory(Zepto, root.mHistory);6	}7}(window, function($, mHistory) {8	$.showTip = function(msg) {9		var pop = $('#commonTipBox');10//                var y = window.scrollY;11//                window.scroll(0,y);12		if(pop.length > 0){13			pop.html(msg).css('display','block');14		}else{15			pop = $('<div id="commonTipBox" class="common-tip-shadow">'+msg+'</div>');16			$('body').append(pop);17		}18		$.popPosition(pop);19		setTimeout(function(){20			pop.css('display','none');21		},2000);22	}23	$.showWrapper = function(callback){24		var wrapper = $('#transWrapper');25		var _H = $(document).height();26		var winH = window.screen.height;27		//var winH = $(window).height();28		//alert(window.screen.height+','+window.screen.availHeight+','+$(window).height()+','+window.innerHeight+','+document.documentElement.clientHeight+','+document.body.clientHeight)29		if(_H < winH) _H = winH;30		if(!wrapper.length){31			wrapper = $('<div id="transWrapper" class="normal-pop-wrapper"></div>');32			$('body').append(wrapper);33		}else{34			wrapper.css('display','block');35		}36		wrapper.css('height',_H + 'px');37		wrapper.on('click',function(){38			$.hidePopUp();39			history.go(-1);40			if (callback && typeof callback == 'function'){ callback()}41		});42	}43	//åºé¨éæ©å表44	$.bottomSelect = function(){45		if(!arguments.length) return false;46		var obj = arguments[0];47		var til,btn,html = '',48			option = obj.option || '',49			val = obj.value || option,50			type = obj.type || 1,51			popClass = obj.popClass || '',52			pop = $('.common-bottom-popup');53		obj.title == 0 ? til = obj.title : til = obj.title || 'è¯·éæ©';54		obj.btn == 0 ? btn = obj.btn : btn = obj.btn || 'åæ¶';55		til == 0 ? html = '<ul>' : html = '<ul><li class="common-bottom-popup-title">'+til+'</li>';56		for(var i = 0;i < option.length;i++){57			html += '<li class="common-bottom-popup-option" data-value="'+ val[i] +'">' + option[i] + '</li>';58		}59		til == 0 ? html += '</ul>' : html += '</ul><div class="common-bottom-popup-cancel-btn">'+ btn +'</div>';60		if(pop.length > 0){61			pop.html(html).attr('id','bottomSelectListPop').addClass(popClass);62		}else{63			pop = $('<div id="bottomSelectListPop" class="common-bottom-popup '+ popClass +'">'+html+'</div>');64			$('body').append(pop);65		}66		$.showWrapper(obj.finish);67		pop.css('bottom','0');68		mHistory.addState({pop:1});69		history.pushState({pop:1},null,null);70		$('#bottomSelectListPop .common-bottom-popup-option').on('click',function(){71			var $this = $(this);72			var val = $this.attr('data-value'),73				option = $this.html();74			$.hidePopUp();75			history.go(-1);76			if(val === 'openAlbum'){77				if (typeof window.MomoBridge == 'object')  {78					MomoBridge.ready(function(BRG){79						BRG.invoke('readImage', {80							//id: 'imgPreview_0',81							id:$this.attr('_imgid'),82							method:1,83							type:'base64'84						},function(id,data,size,type){85							if(!data) return false;86							$('#'+id)[0].src="data:image/jpeg;base64,"+data;87							var src = $('#'+id)[0].src;88							if(window.setImageCallback) setImageCallback(id,src,data);89						})90					})91				} else {92					momo_btn_controller.controller_init_callback=function(){93						momo_btn_controller.readImage(JSON.stringify({94							//id: 'imgPreview_0',95							id:$this.attr('_imgid'),96							method:1,97							type:'base64'98						}));99					};100					momo_btn_controller.momo_btn_controller_init();101				}102			}else if(val === 'openCamera'){103				if (typeof window.MomoBridge == 'object')  {104					MomoBridge.ready(function(BRG){105						BRG.invoke('readImage', {106							//id: 'imgPreview_0',107							id:$this.attr('_imgid'),108							method:2,109							type:'base64'110						},function(id,data,size,type){111							if(!data) return false;112							$('#'+id)[0].src="data:image/jpeg;base64,"+data;113							var src = $('#'+id)[0].src;114							if(window.setImageCallback) setImageCallback(id,src,data);115						})116					})117				} else {118					momo_btn_controller.controller_init_callback=function(){119						momo_btn_controller.readImage(JSON.stringify({120							//id: 'imgPreview_0',121							id:$this.attr('_imgid'),122							method:2,123							type:'base64'124						}));125					};126					momo_btn_controller.momo_btn_controller_init();127				}128			} else {129				if(typeof obj.callback === 'function'){130					switch(type){131						case 1:132							obj.callback(val);133							break;134						case 2:135							obj.callback(option);136							break;137						case 3:138							obj.callback(val,option);139							break;140					}141				}142			}143			if(typeof obj.finish === 'function'){obj.finish();}144		})145		pop.find('.common-bottom-popup-cancel-btn').on('click',function(){146			$.hidePopUp();147			history.go(-1);148			if(typeof obj.cancel === 'function'){obj.cancel();}149		})150		return pop.find('.common-bottom-popup-option');151	}152	//ç±»confirmå¼¹çª153	$.confirm = function(){154		if(!arguments.length) return false;155		var obj = arguments[0];156		var b1 = obj.btn1 || 'åæ¶';157		var b2 = obj.btn2 || 'ç¡®å®';158		var tit = obj.title || 'æç¤º';159		var popClass = obj.popClass || '';160		var pop = $('.common-popup');161		var html = '<div class="title">'+tit+'</div><div class="content">'+obj.content+'</div>';162		html += '<div class="btns mt55 clearfix"><div class="panel-col-50"><a class="btn metrobtn btn1 confirm-btn-left">'+b1+'</a></div><div class="panel-col-50"><a class="btn metrobtn last btn2 confirm-btn-right" ">'+b2+'</a></div></div>';163		setTimeout(function(){164			if(pop.length > 0){165				pop.html(html).attr('id','confirmPop').css('display','block');166			}else{167				pop = $('<div id="confirmPop" class="common-popup '+ popClass +'">'+html+'</div>');168				$('body').append(pop);169			}170			$.showWrapper(obj.finish);171			$.popPosition(pop);172			console.log('add')173			console.log(mHistory.state)174			mHistory.addState({pop:1});175			history.pushState({pop:1},null,null);176			$('#confirmPop .confirm-btn-right').on('click',function(){177				var $this = $(this);178				history.go(-1);179				if(typeof obj.callback === 'function'){obj.callback.call($this);}180				if(typeof obj.success === 'function'){obj.success.call($this);}181				if(typeof obj.finish === 'function'){obj.finish();}182				$.hidePopUp();183			});184			$('#confirmPop .confirm-btn-left').on('click',function(){185				var $this = $(this);186				history.go(-1);187				if(typeof obj.callback2 === 'function'){obj.callback2.call($this);}188				if(typeof obj.fail === 'function'){obj.fail.call($this);}189				if(typeof obj.finish === 'function'){obj.finish();}190				$.hidePopUp();191			});192		},200)193	}194	//ç±»alertå¼¹çª195	$.alert = function(){196		if(!arguments.length) return false;197		var obj = arguments[0];198		var b = obj.btn || 'ç¡®å®';199		var til = obj.title || 'æç¤º';200		var popClass = obj.popClass || '';201		var pop = $('.common-popup');202		var html = '<div class="title">'+til+'</div><div class="content">'+obj.content+'</div>';203		html+= '<div class="btns mt55"><a href="javascript:;" class="btn metrobtn only close-alert-pop">'+b+'</a></div>';204		setTimeout(function(){205			if(pop.length > 0){206				pop.html(html).attr('id','alertPop').css('display','block');207			}else{208				pop = $('<div id="alertPop" class="common-popup '+ popClass +'">'+html+'</div>');209				$('body').append(pop);210			}211			$.showWrapper(obj.finish);212			$.popPosition(pop);213			mHistory.addState({pop:1});214			history.pushState({pop:1},null,null);215			$('#alertPop .close-alert-pop').on('click',function(){216				var $this = $(this);217				history.go(-1);218				if(typeof obj.callback === 'function'){obj.callback.call($this);}219				if(typeof obj.finish === 'function'){obj.finish();}220				$.hidePopUp();221			});222		},200)223	}224	$.showOptions = function(){225		if(!arguments.length) return false;226		var obj = arguments[0];227		var til = obj.title || 'è¯·éæ©',228			option = obj.option || '',229			val = obj.value || option,230			type = obj.type || 1,231			pop = $('.common-popup');232		var html = '<div class="title">'+til+'</div><div class="options-pop-list">';233		for(var i = 0;i < option.length;i++){234			html += '<div class="option-pop-content" data-value="'+ val[i] +'">' + option[i] + '</div>';235		}236		html+= '</div>';237		if(pop.length > 0){238			pop.html(html).attr('id','selectListPop').css('display','block');239		}else{240			pop = $('<div id="selectListPop" class="common-popup">'+html+'</div>');241			$('body').append(pop);242		}243		$.showWrapper(obj.finish);244		$.popPosition(pop);245		mHistory.addState({pop:1});246		history.pushState({pop:1},null,null);247		$('#selectListPop .option-pop-content').on('click',function(){248			var $this = $(this);249			var val = $this.attr('data-value'),250				option = $this.html();251			$.hidePopUp();252			history.go(-1);253			if(val === 'openAlbum'){254				if (typeof window.MomoBridge == 'object')  {255					MomoBridge.ready(function(BRG){256						BRG.invoke('readImage', {257							//id: 'imgPreview_0',258							id:$this.attr('_imgid'),259							method:1,260							type:'base64'261						},function(id,data,size,type){262							if(!data) return false;263							$('#'+id)[0].src="data:image/jpeg;base64,"+data;264							var src = $('#'+id)[0].src;265							if(window.setImageCallback) setImageCallback(id,src,data);266						})267					})268				} else {269					momo_btn_controller.controller_init_callback=function(){270						momo_btn_controller.readImage(JSON.stringify({271							//id: 'imgPreview_0',272							id:$this.attr('_imgid'),273							method:1,274							type:'base64'275						}));276					};277					momo_btn_controller.momo_btn_controller_init();278				}279			}else if(val === 'openCamera'){280				if (typeof window.MomoBridge == 'object')  {281					MomoBridge.ready(function(BRG){282						BRG.invoke('readImage', {283							//id: 'imgPreview_0',284							id:$this.attr('_imgid'),285							method:2,286							type:'base64'287						},function(id,data,size,type){288							if(!data) return false;289							$('#'+id)[0].src="data:image/jpeg;base64,"+data;290							var src = $('#'+id)[0].src;291							if(window.setImageCallback) setImageCallback(id,src,data);292						})293					})294				} else {295					momo_btn_controller.controller_init_callback=function(){296						momo_btn_controller.readImage(JSON.stringify({297							//id: 'imgPreview_0',298							id:$this.attr('_imgid'),299							method:2,300							type:'base64'301						}));302					};303					momo_btn_controller.momo_btn_controller_init();304				}305			} else {306				if(typeof obj.callback === 'function'){307					if(type == 1){308						obj.callback(val);309					}else if(type == 2){310						obj.callback(option);311					}else{312						obj.callback(val,option);313					}314				}315			}316			if(typeof obj.finish === 'function'){obj.finish();}317		})318		return pop.find('.option-pop-content');319	}...pop.js
Source:pop.js  
...272    };273    //注å$æä»¶274    $.fn.pop = function (opts) {275        opts = $.extend(opts, { ref : this[0] });276        return new pop(opts);277    };278    module.exports = function(opts){279        return new pop(opts);280    };...NotyPopLoadTemplate.js
Source:NotyPopLoadTemplate.js  
1// ç¹å»éç¥å¼¹çªä¸è½½æ¨¡æ¿2'use strict';3var util = require('util');4var GtReq = require('../GtReq');5var BaseTemplate = require('./BaseTemplate');6function NotPopLoadTemplate(options) {7    BaseTemplate.call(this, options);8    options = util._extend({9        notyIcon: '',           //éç¥æ å¾æ 10        logoUrl: '',            //ä»ç½ç»è·å徿 11        notyTitle: '',          //éç¥æ æ é¢12        notyContent: '',        //éç¥æ å
容13        isVibrate: true,14        isClearable: true,      //éç¥æ¯å¦å¯æ¸
é¤15        isRing: true,16        popTitle: '',           //å¼¹æ¡æ é¢17        popContent: '',         //å¼¹æ¡å
容18        popImage: '',           //å¼¹æ¡å¾ç19        popButton1: '',         //左边æé®åç§°20        popButton2: '',         //å³è¾¹æé®åç§°21        loadIcon: '',           //ä¸è½½å¾æ 22        loadTitle: '',          //ä¸è½½æ é¢23        loadUrl: '',            //ä¸è½½å°å24        isAutoInstall: false,   //æ¯å¦èªå¨å®è£
25        isActived: false,       //æ¯å¦æ¿æ´»26        androidMark: '',        //å®åæ è¯27        symbianMark: '',        //å¡çæ è¯28        iphoneMark: ''          //è¹ææ è¯29    }, options);30    util._extend(this, options);31}32util.inherits(NotPopLoadTemplate, BaseTemplate);33NotPopLoadTemplate.prototype.getActionChain = function() {34    // 设置actionChain35    // Set actionChain36    var actionChain = new GtReq.ActionChain({37        actionId: 1,38        type: GtReq.ActionChain.Type.Goto,39        next: 1000040    });41    var actionChain1 = new GtReq.ActionChain({42        actionId: 10000,43        type: GtReq.ActionChain.Type.notification,44        title: this.notyTitle,45        text: this.notyContent,46        logo: this.notyIcon,47        logoURL: this.logoUrl,48        ring: this.isRing,49        clearable: this.isClearable,50        buzz: this.isVibrate,51        next: 1001052    });53    // éç¥54    // Notification55    var actionChain2 = new GtReq.ActionChain({56        actionId: 10001,57        type: GtReq.ActionChain.Type.notification,58        title: this.notyTitle,59        text: this.notyContent,60        logo: this.notyIcon,61        ring: this.isRing,62        clearable: true,63        buzz: true,64        next: 1001065    });66    var actionChain3 = new GtReq.ActionChain({67        actionId: 10010,68        type: GtReq.ActionChain.Type.Goto,69        next: 1002070    });71    //å¼¹æ¡æé®72    var button1 = new GtReq.Button({73        text: this.popButton1,74        next: 1004075    });76    var button2 = new GtReq.Button({77        text: this.popButton2,78        next: 10079    });80    //å¼¹æ¡81    var actionChain4 = new GtReq.ActionChain({82        actionId: 10020,83        type: GtReq.ActionChain.Type.popup,84        title: this.popTitle,85        text: this.popContent,86        img: this.popImage,87        buttons: [button1, button2],88        next: 689    });90    //appstartupid91    var appStartUp = new GtReq.AppStartUp({92        android: this.androidMark,93        ios: this.iphoneMark,94        symbia: this.symbianMark95    });96    var actionChain5 = new GtReq.ActionChain({97        actionId: 10040,98        type: GtReq.ActionChain.Type.appdownload,99        name: this.loadTitle,100        url: this.loadUrl,101        logo: this.loadIcon,102        autoInstall: this.isAutoInstall,103        autostart: this.isActived,104        appstartupid: appStartUp,105        next: 100106    });107    var actionChain6 = new GtReq.ActionChain({108        actionId: 100,109        type: GtReq.ActionChain.Type.eoa110    });111    var actionChains = [actionChain, actionChain1, actionChain2, actionChain3, actionChain4, actionChain5, actionChain6];112    return actionChains;113};114NotPopLoadTemplate.prototype.getPushType = function() {115    return 'NotyPopLoad';116};117/**118 * 设置éç¥æ å¾æ 119 *120 * @param notyIcon121 */122NotPopLoadTemplate.prototype.setNotyIcon = function(notyIcon) {123    this.notyIcon = notyIcon;124    return this;125};126NotPopLoadTemplate.prototype.setLogoUrl = function(logoUrl) {127    this.logoUrl = logoUrl;128    return this;129};130/**131 * 设置éç¥æ æ é¢132 *133 * @param notyTitle134 */135NotPopLoadTemplate.prototype.setNotyTitle = function(notyTitle) {136    this.notyTitle = notyTitle;137    return this;138};139/**140 * 设置éç¥æ å
容141 *142 * @param notyContent143 */144NotPopLoadTemplate.prototype.setNotyContent = function(notyContent) {145    this.notyContent = notyContent;146    return this;147};148/**149 * éç¥æ¯å¦å¯æ¸
é¤150 *151 * @param isClearable152 */153NotPopLoadTemplate.prototype.setIsClearable = function(isClearable) {154    this.isClearable = isClearable;155    return this;156};157/**158 * æ¯å¦åé159 *160 * @param isRing161 */162NotPopLoadTemplate.prototype.setIsRing = function(isRing) {163    this.isRing = isRing;164    return this;165};166/**167 * æ¯å¦éå¨168 *169 * @param isVibrate170 */171NotPopLoadTemplate.prototype.setIsVibrate = function(isVibrate) {172    this.isVibrate = isVibrate;173    return this;174};175/**176 * è®¾ç½®å¼¹æ¡æ é¢177 *178 * @param popTitle179 */180NotPopLoadTemplate.prototype.setPopTitle = function(popTitle) {181    this.popTitle = popTitle;182    return this;183};184/**185 * 设置弹æ¡å
容186 *187 * @param popContent188 */189NotPopLoadTemplate.prototype.setPopContent = function(popContent) {190    this.popContent = popContent;191    return this;192};193/**194 * 设置弹æ¡å¾ç195 *196 * @param popImage197 */198NotPopLoadTemplate.prototype.setPopImage = function(popImage) {199    this.popImage = popImage;200    return this;201};202/**203 * 设置左边æé®åç§°204 *205 * @param popButton1206 */207NotPopLoadTemplate.prototype.setPopButton1 = function(popButton1) {208    this.popButton1 = popButton1;209    return this;210};211/**212 * 设置å³è¾¹æé®åç§°213 *214 * @param popButton2215 */216NotPopLoadTemplate.prototype.setPopButton2 = function(popButton2) {217    this.popButton2 = popButton2;218    return this;219};220/**221 * 设置ä¸è½½å¾æ 222 *223 * @param loadIcon224 */225NotPopLoadTemplate.prototype.setLoadIcon = function(loadIcon) {226    this.loadIcon = loadIcon;227    return this;228};229/**230 * 设置ä¸è½½æ é¢231 *232 * @param loadTitle233 */234NotPopLoadTemplate.prototype.setLoadTitle = function(loadTitle) {235    this.loadTitle = loadTitle;236    return this;237};238/**239 * 设置ä¸è½½å°å240 *241 * @param loadUrl242 */243NotPopLoadTemplate.prototype.setLoadUrl = function(loadUrl) {244    this.loadUrl = loadUrl;245    return this;246};247/**248 * 设置æ¯å¦èªå¨å®è£
249 *250 * @param isAutoInstall251 */252NotPopLoadTemplate.prototype.setAutoInstall = function(isAutoInstall) {253    this.isAutoInstall = isAutoInstall;254    return this;255};256/**257 * 设置æ¯å¦æ¿æ´»258 *259 * @param isActived260 */261NotPopLoadTemplate.prototype.setActived = function(isActived) {262    this.isActived = isActived;263    return this;264};265/**266 * 设置å®åæ è¯267 *268 * @param androidMark269 */270NotPopLoadTemplate.prototype.setAndroidMark = function(androidMark) {271    this.androidMark = androidMark;272    return this;273};274/**275 * 设置å¡çæ è¯276 *277 * @param symbianMark278 */279NotPopLoadTemplate.prototype.setSymbianMark = function(symbianMark) {280    this.symbianMark = symbianMark;281    return this;282};283/**284 * è®¾ç½®è¹ææ è¯285 *286 * @param iphoneMark287 */288NotPopLoadTemplate.prototype.setIphoneMark = function(iphoneMark) {289    this.iphoneMark = iphoneMark;290    return this;291};...myscript.js
Source:myscript.js  
1// shim layer with setTimeout fallback2window.requestAnimFrame = (function(){3  return  window.requestAnimationFrame       ||  4          function( callback ){5            window.setTimeout(callback, );6          };7})();8// namespace our game9var POP = {10    // set up some inital values11    m: true,12    WIDTH: 360, 13    HEIGHT:  540, 14    scale:  1,15    // the position of the canvas16    // in relation to the screen17    offset: {top: 0, left: 0},18    // store all bubble, touches, particles etc.19	colorArray:null,20	grid: new Array(8),21    // the amount of game ticks until22    // we spawn a bubble23    // for tracking player's progress24    // we'll set the rest of these25    // in the init function26    currentWidth:  null,27    currentHeight:  null,28    canvas: null,29    ctx:  null,30	numPlayers:2,31	currentPlayer:null,32	myTurn:true,33	temp:null,34	ifFinished:false,35	firstMove: new Array(),36    init: function() {37		POP.colorArray=["#ff0000","#0000ff","#976","#abff00","#c71585","#008080"];38		POP.currentPlayer=0;39		var i;40		POP.firstMove[POP.numPlayers];41		for (i=0;i<POP.numPlayers;i++){42			POP.firstMove[i]=false;43		}44		for (i=0;i<8;i=i+1){45			POP.grid[i] = [[0,7],[0,7],[0,7],[0,7],[0,7],[0,7],[0,7],[0,7]];46		};47		48        // the proportion of width to height49        POP.RATIO = POP.WIDTH / POP.HEIGHT;50        // these will change when the screen is resize51        52        // this is our canvas element53        POP.canvas = document.getElementsByTagName('canvas')[0];54        // it's important to set this55        // otherwise the browser will56        // default to 320x20057        58        // the canvas context allows us to 59        // interact with the canvas api60        POP.ctx = POP.canvas.getContext('2d');61        62		window.addEventListener('click', function(e) {63            e.preventDefault();64            POP.Input.set(e);65        },);66        // listen for touches67        68        // we're ready to resize69        POP.resize();70        POP.loop();71    },72	73	update: function() {74		var i;75		if (POP.Input.tapped) {76            // keep track of taps; 77            // set tapped back to false78            // to avoid spawning a new touch79            // in the next cycle80            POP.Input.tapped = false;81			if(POP.myTurn&&(ifValidMove(Math.floor(POP.Input.x/45),Math.floor(POP.Input.y/45)))){82				goToNextState(Math.floor(POP.Input.x/45),Math.floor(POP.Input.y/45),POP.currentPlayer,false);83				POP.currentPlayer = (POP.currentPlayer + 1)%POP.numPlayers;84			}85        }86	},87	88	render: function() {89        var i;90		POP.Draw.rect(0, 0, POP.WIDTH, POP.HEIGHT, '#000');91		POP.ctx.strokeStyle=POP.colorArray[(POP.currentPlayer)%POP.numPlayers]; 92		POP.ctx.lineWidth=2;93		for (i=0;i<=360;i=i+360/8){94			POP.ctx.moveTo(i,0);95			POP.ctx.lineTo(i,360);96			POP.ctx.stroke();97		}98		for(i=0;i<=360;i=i+360/8){99			POP.ctx.moveTo(0,i);100			POP.ctx.lineTo(360,i);101			POP.ctx.stroke();102		}103		104		for(var i=0;i<8;i++){105			for(var j=0;j<8;j++){106				if(POP.grid[i][j][0]==1){107					POP.Draw.circle(i*45+15,j*45+15,7,POP.colorArray[POP.grid[i][j][1]]);108				}109				else if(POP.grid[i][j][0]==2){110					POP.Draw.circle(i*45+10,j*45+10,7,POP.colorArray[POP.grid[i][j][1]]);111					POP.Draw.circle(i*45+15,j*45+15,7,POP.colorArray[POP.grid[i][j][1]]);112				}113				else if(POP.grid[i][j][0]==3){114					POP.Draw.circle(i*45+15,j*45+15,7,POP.colorArray[POP.grid[i][j][1]]);115					POP.Draw.circle(i*45+20,j*45+20,7,POP.colorArray[POP.grid[i][j][1]]);116					POP.Draw.circle(i*45+30,j*45+30,7,POP.colorArray[POP.grid[i][j][1]]);117				}118			}119		}120		if(POP.ifFinished){121            if(POP.m==true){122                document.getElementById('clap').play();123                POP.m=false;124            }125			POP.Draw.rect(0, 0, POP.WIDTH, POP.HEIGHT, '#000');126			POP.Draw.text("Player " + POP.currentPlayer +" Won!", 90,270,30,"#fff");127		}128		},129	130	loop: function() {131        requestAnimFrame( POP.loop );132        POP.update();133        POP.render();134    },135	resize: function() {136    137        POP.currentHeight = window.innerHeight;138        // resize the width in proportion139        // to the new height140        POP.currentWidth = POP.currentHeight * POP.RATIO;141        // set the new canvas style width & height142        // note: our canvas is still 320x480 but143        // we're essentially scaling it with CSS144        POP.canvas.style.width = POP.currentWidth + 'px';145        POP.canvas.style.height = POP.currentHeight + 'px';146        // the amount by which the css resized canvas147        // is different to the actual (480x320) size.148        POP.scale = POP.currentWidth / POP.WIDTH;149        // position of canvas in relation to150        // the screen151        POP.offset.top = POP.canvas.offsetTop;152        POP.offset.left = POP.canvas.offsetLeft;153    },154	155};	156POP.Draw = {157    clear: function() {158        POP.ctx.clearRect(0, 0, POP.WIDTH, POP.HEIGHT);159    },160    rect: function(x, y, w, h, col) {161        POP.ctx.fillStyle = col;162        POP.ctx.fillRect(x, y, w, h);163    },164    circle: function(x, y, r, col) {165        POP.ctx.fillStyle = col;166        POP.ctx.beginPath();167        POP.ctx.arc(x + 5, y + 5, r, 0,  Math.PI * 2, true);168        POP.ctx.fill();169    },170    text: function(string, x, y, size, col) {171        POP.ctx.font = 'bold '+size+'px Monospace';172        POP.ctx.fillStyle = col;173        POP.ctx.fillText(string, x, y);174    }175};176var ifCorner = function(a,b){177	if((a==0)&&(b==0)){178		return true;}179	else if((a==0)&&(b==7)){180		return true;}181	else if((a==7)&&(b==0)){182		return true;}183	else if((a==7)&&(b==7)){184		return true;}185	else{186		return false;};187	}188var ifEdge = function(a,b){189	if(!ifCorner(a,b)&&((a==0)||(b==0)||(a==7)||(b==7))){190		return true;191	}192	else{193		return false;194	}195	}196	197var ifTerminate = function(currentPlayer){198	if(POP.firstMove[currentPlayer]==false){199		POP.firstMove[currentPlayer]=true;200		return false;201	}202	else{203		var result = true;204		for(var i=0;i<8;i++){205			for(var j=0;j<8;j++){206				if(POP.grid[i][j][1]!=currentPlayer&&(!(POP.grid[i][j][0]==0))){207					result = false;208				}209			}210		}211	return result;212	}213}	214	215var ifValidMove = function(x,y){216	if((POP.grid[x][y][0]==0)||(POP.grid[x][y][1]==POP.currentPlayer)){217		return true;218	}219	else{220		return false;221	};222	223}224	225var goToNextState = function(x,y,currentPlayer,ifNuclear){226        document.getElementById('split').play();227        POP.grid[x][y][1]=currentPlayer;228		POP.grid[x][y][0]+=1;229			var ifFull = false;230			if (ifCorner(x,y)&&POP.grid[x][y][0]>1){231				ifFull = true;232			}233			else if((ifEdge(x,y))&&(POP.grid[x][y][0]>2)){234				ifFull = true;235			}236			else if(POP.grid[x][y][0]>3){237				ifFull = true;238			}239			var possible = [[x,y+1],[x,y-1],[x+1,y],[x-1,y]];240			if(ifFull){241				for(var i=0;i<4;i++){242					if((possible[i][0]>=0)&&(possible[i][0]<=7)&&(possible[i][1]>=0)&&(possible[i][1]<=7)){243						POP.grid[x][y][0] -= 1;244						goToNextState(possible[i][0],possible[i][1],currentPlayer,true);245						246					}247				}248			}249			if (ifTerminate(currentPlayer)){250			POP.render();251			POP.ifFinished=true;252			}253};254POP.Input = {255    x: 0,256    y: 0,257    tapped :false,258    set: function(data) {259        this.x = (data.pageX - POP.offset.left) / POP.scale;260        this.y = (data.pageY - POP.offset.top) / POP.scale;261        this.tapped = true;262    }263};...pop.router.js
Source:pop.router.js  
1POP.router = function() {2    window.scrollTo(0,1);3    POP.timer = new Date().getTime() * 0.002;4    POP.draw.clear();5    switch(POP.state) {6    7        case 'splash':8            POP.splash(); 9        break;10        case 'gameOver':11            POP.gameOver(); 12        break;13        case 'hiScores':14            POP.hiScores();15        break;16        default:17            POP.play();18        break;19    }20    POP.m.click = false;21    POP.stats.update();22    requestAnimFrame(POP.router);23};24POP.splash = function() {25    var opacity = Math.abs(Math.sin(POP.timer * 0.8)),26        col = 'rgba(255,255,255,'+opacity+')';27    POP.delay += 1;28	29	/*30    if (POP.ua.appleMobile === true && window.navigator.standalone === false) {31        POP.draw.rect(0,0,POP.W, 30, 'rgba(0,0,0,0.2)'); 32        POP.draw.text(40,20, 'Psst! Save to homepage for full screen fun!', 10, '#fff');33    } else if (POP.Ua.hasTouch === false) {34        POP.draw.text(20,POP.H - 20, 'This game is much more fun on touch devices', 11, 'rgba(255,255,255,0.5)');35    }*/36    POP.draw.text(45,135,'æ³æ³¡æ³¡ï¼',64, 'rgba(0,0,0,0.3)');37    POP.draw.text(40,130,'æ³æ³¡æ³¡ï¼',64);38    POP.draw.text(110,240, POP.Ua.action + 'å¼å§æ¸¸æ', 16, col);39    POP.draw.text(128, 340, 'æé«å', 20, 'rgba(255,255,255,0.8)');40    POP.draw.text("center", 380, POP.hiScore.toString(), 24, 'rgba(255,255,255,0.8)');41    if (POP.m.click && POP.delay > 20) {42        POP.textLayer.style.display = 'none';43        POP.delay = 0;44        POP.touches = [];45        POP.state = 'play';46        POP.gameStart = new Date().getTime();47    }48};49POP.gameOver = function() {50    var opacity = Math.abs(Math.sin(POP.timer * 0.8)),51        col = 'rgba(255,255,255,'+opacity+')',52        col2 = 'rgba(172,255,4,1)';53    POP.delay += 1;54    POP.draw.text(40,90,'Game Over',40, col);55    // display scores56	POP.draw.text(115,160,'泡泡æ°: '+POP.score.burst, 16, '#fff');57    POP.draw.text(115,190,'ç²¾å度: ' + POP.score.accuracy + '%', 16, '#fff'); 58    POP.draw.text(131,220,'æ¶é´: ' + POP.score.seconds, 16, '#fff'); 59    POP.draw.text("center",270,'' + POP.score.total, 30, '#fff'); 60    if (POP.newHiscore) {61        POP.draw.text('center', 310, 'æ°è®°å½!!!', 20, col2);62        // POP.draw.text('center', 320, POP.score.total.toString(), 20, col2);63    }64	// ç»ç»æ´å¤æ¸¸æ65	//POP.draw.rect(10, 330, 50, 20, "#fff")66	67	POP.inputBox.style.display = "block";68	// POP.state = 'splash'; å°±æ¯éæ°å¼å§æ¸¸æ69	70    if (POP.m.click && POP.delay > 100) {71        POP.againGame();72    }73	74	if(!POP.isEndGame){75		POP.isEndGame = true;76		//btGame.setShare({title: "æ³æ³¡æ³¡æ³ä¸ç¾äºï¼æ¿äº"+POP.score.total+"åãä½ è¦ä¸è¦æ¥ç½ä¸æï¼"});77		//btGame.playScoreMsg("泡泡å
æå°±æ¯ä½ ï¼æ¿äº"+POP.score.total+"åï¼ä¸å»ç«èä¸ä¸åï¼");78		dp_submitScore(POP.score.total);79	}80	81};82POP.isEndGame = false;83POP.againGame = function(){84	/*POP.isEndGame = false;85	POP.score.taps =86	POP.score.burst =87	POP.score.escapees =88	POP.score.accuracy =89	POP.score.seconds = 0;90	POP.newHiscore = false;91	POP.lives = POP.MAX_LIVES;92	POP.level = 1;93	POP.delay = 0;94	POP.gameStart = null;95	POP.inputBox.style.display = 'none';96	POP.state = 'splash';*/97	location.reload();98}99POP.hiScores = function() {100    if (POP.m.click) {101        POP.state = 'splash';102    }103    POP.draw.text('center',50,'Hi-Scores',40, '#fff');104};105POP.play = function() {106    var i, accuracy, live_col, bubble_speed;107    POP.secsElapsed = ( new Date().getTime() - POP.gameStart ) / 1000;108    POP.level = ~~(POP.secsElapsed / 10) + 1;109    110    if (POP.nextBubble < 0) {111        POP.nextBubble = POP.rnd(30 - POP.level, 10); 112        bubble_speed = POP.rnd(5 + POP.level) * -1;113        POP.bubbles.push(new POP.Bubble());114    }115    POP.nextBubble--;116    if (POP.m.click === true) {117        POP.score.taps += 1;118        POP.touches.push( new POP.Touch(POP.m.x, POP.m.y) );119    }120    // render bonus121    POP.bonus.render();122    if (POP.bonus.collides()) {123        switch (POP.bonus.type.action) {124            case 'green':125                POP.lives = POP.MAX_LIVES;126            break;127            case 'red':128                for (i = 0; i < POP.bubbles.length; i += 1) {129                    POP.bubbles[i].burst();130                }131            break;132            case 'black':133                POP.lives -= 1;134            break;135        }136        POP.bonus.reset();137    }138    // render all touches139    for (i = 0; i < POP.touches.length; i += 1) {140        POP.touches[i].render();141        if (POP.touches[i].remove) {142            POP.touches.splice(i, 1);143        }144    }145    // render all bubbles146    for (i = 0; i < POP.bubbles.length; i += 1) {147        POP.bubbles[i].move().render().checkCollision(); 148        if (POP.bubbles[i].remove) {149            POP.bubbles.splice(i, 1);150        }151    }152    // render all explosions153    for (i = 0; i < POP.explosions.length; i += 1) {154            POP.explosions[i].move();155            if (POP.explosions[i].finished) {156                POP.explosions.splice(i, 1);157            }158    }159    // display crappy wave effect160    for (i = 0; i < POP.wave.total; i++) {161        var x_offset = Math.sin(POP.timer * 0.8) * 10;162        POP.draw.circle(163                    POP.wave.x + x_offset +  (i * POP.wave.r), 164                    POP.wave.y, 165                    POP.wave.r, 166                    '#fff'); 167    }168    // calculate score169    POP.score.seconds = ~~(( new Date().getTime() - POP.gameStart ) / 1000);170    POP.score.total = ~~( POP.score.seconds + (POP.score.burst * 10) );171    POP.draw.text(20,40, POP.score.total.toString(), 22, '#fff');172    // draw lives173    for (i = 1; i <= POP.MAX_LIVES; i++) {174        live_col = (i > POP.lives) ? 'rgba(0,0,0,0.7)' : 'rgba(173,255,4,0.7)';175        POP.draw.circle( (i * 25) + (POP.W - 100), 30, 10, live_col); 176    }177    if (POP.lives <= 0) {178        POP.bubbles = [];179        POP.touches = [];180        POP.explosions = [];181        POP.state = 'gameOver';182        POP.secsElapsed = 0;183        POP.level = 0;184        POP.bonus.reset();185        POP.textLayer.style.display = 'block';186        // calculate final score187        POP.score.accuracy = ~~((POP.score.burst / POP.score.taps) * 100);188        if (POP.score.accuracy > 100) {189            POP.score.accuracy = 100;190        }191        POP.score.accuracy = (POP.score.burst === 0) ? 0 :POP.score.accuracy;192        POP.score.seconds = ~~(( new Date().getTime() - POP.gameStart ) / 1000);193        POP.score.total = ~~(POP.score.burst * 10) + 194                            (POP.score.seconds * 1);195        if (POP.score.total > POP.hiScore) {196            POP.newHiscore = true;197            POP.hiScore = POP.score.total;198			try{199				localStorage.POP_hiScore = POP.score.total;200			}catch(e){201				console.log(e);202			}203        }204    }...test.js
Source:test.js  
1/* jshint node: true, unused: true, undef: true */2/* globals it */3var assert = require('assert');4var EvEmitter = require('../ev-emitter');5it( 'should emitEvent', function() {6  var emitter = new EvEmitter();7  var didPop;8  emitter.on( 'pop', function() {9    didPop = true;10  });11  emitter.emitEvent( 'pop' );12  assert.ok( didPop, 'event emitted' );13});14it( 'emitEvent should pass argument to listener', function() {15  var emitter = new EvEmitter();16  var result;17  function onPop( arg ) {18    result = arg;19  }20  emitter.on( 'pop', onPop );21  emitter.emitEvent( 'pop', [ 1 ] );22  assert.equal( result, 1, 'event emitted, arg passed' );23});24it( 'does not allow same listener to be added', function() {25  var emitter = new EvEmitter();26  var ticks = 0;27  function onPop() {28    ticks++;29  }30  emitter.on( 'pop', onPop );31  emitter.on( 'pop', onPop );32  var _onPop = onPop;33  emitter.on( 'pop', _onPop );34  emitter.emitEvent('pop');35  assert.equal( ticks, 1, '1 tick for same listener' );36});37it( 'should remove listener with .off()', function() {38  var emitter = new EvEmitter();39  var ticks = 0;40  function onPop() {41    ticks++;42  }43  emitter.on( 'pop', onPop );44  emitter.emitEvent('pop');45  emitter.off( 'pop', onPop );46  emitter.emitEvent('pop');47  assert.equal( ticks, 1, '.off() removed listener' );48  // reset49  var ary = [];50  ticks = 0;51  emitter.allOff();52  function onPopA() {53    ticks++;54    ary.push('a');55    if ( ticks == 2 ) {56      emitter.off( 'pop', onPopA );57    }58  }59  function onPopB() {60    ary.push('b');61  }62  emitter.on( 'pop', onPopA );63  emitter.on( 'pop', onPopB );64  emitter.emitEvent('pop'); // a,b65  emitter.emitEvent('pop'); // a,b - remove onPopA66  emitter.emitEvent('pop'); // b67  assert.equal( ary.join(','), 'a,b,a,b,b', '.off in listener does not interfer' );68});69it( 'should handle once()', function() {70  var emitter = new EvEmitter();71  var ary = [];72  emitter.on( 'pop', function() {73    ary.push('a');74  });75  emitter.once( 'pop', function() {76    ary.push('b');77  });78  emitter.on( 'pop', function() {79    ary.push('c');80  });81  emitter.emitEvent('pop');82  emitter.emitEvent('pop');83  assert.equal( ary.join(','), 'a,b,c,a,c', 'once listener triggered once' );84  // reset85  emitter.allOff();86  ary = [];87  // add two identical but not === listeners, only do one once88  emitter.on( 'pop', function() {89    ary.push('a');90  });91  emitter.once( 'pop', function() {92    ary.push('a');93  });94  emitter.emitEvent('pop');95  emitter.emitEvent('pop');96  assert.equal( ary.join(','), 'a,a,a', 'identical listeners do not interfere with once' );97});98it( 'does not infinite loop in once()', function() {99  var emitter = new EvEmitter();100  var ticks = 0;101  function onPop() {102    ticks++;103    if ( ticks < 4 ) {104      emitter.emitEvent('pop');105    }106  }107  emitter.once( 'pop', onPop );108  emitter.emitEvent('pop');109  assert.equal( ticks, 1, '1 tick with emitEvent in once' );110});111it( 'handles emitEvent with no listeners', function() {112  var emitter = new EvEmitter();113  assert.doesNotThrow( function() {114    emitter.emitEvent( 'pop', [ 1, 2, 3 ] );115  });116  function onPop() {}117  emitter.on( 'pop', onPop );118  emitter.off( 'pop', onPop );119  assert.doesNotThrow( function() {120    emitter.emitEvent( 'pop', [ 1, 2, 3 ] );121  });122  emitter.on( 'pop', onPop );123  emitter.emitEvent( 'pop', [ 1, 2, 3 ] );124  emitter.off( 'pop', onPop );125  assert.doesNotThrow( function() {126    emitter.emitEvent( 'pop', [ 1, 2, 3 ] );127  });128});129it( 'removes all listeners after allOff', function() {130  var emitter = new EvEmitter();131  var ary = [];132  emitter.on( 'pop', function() {133    ary.push('a');134  });135  emitter.on( 'pop', function() {136    ary.push('b');137  });138  emitter.once( 'pop', function() {139    ary.push('c');140  });141  emitter.emitEvent('pop');142  emitter.allOff();143  emitter.emitEvent('pop');144  assert.equal( ary.join(','), 'a,b,c', 'allOff removed listeners' );...popup.js
Source:popup.js  
1       var pop =null;2       function ShowIframe(title,contentUrl,width,height)3        {4    	   5           pop=new Popup({ contentType:1,isReloadOnClose:false,width:width,height:height});6           pop.setContent("contentUrl",contentUrl);7           pop.setContent("title",title);8           pop.build();9           pop.show();10           11        }12        function ShowHtmlString(title,strHtml,width,height)13        {14            pop=new Popup({ contentType:2,isReloadOnClose:false,width:width,height:height});15            pop.setContent("contentHtml",strHtml);16            pop.setContent("title",title);17            pop.build();18            pop.show();19            20       }21        function ShowConfirm(title,confirmCon,id,str,width,height)22        {23            var pop=new Popup({ contentType:3,isReloadOnClose:false,width:width,height:height});24            pop.setContent("title",title);25            pop.setContent("confirmCon",confirmCon);26            pop.setContent("callBack",ShowCallBack);27            pop.setContent("parameter",{id:id,str:str,obj:pop});28            pop.build();29            pop.show();30        }31        function ShowAlert(title,alertCon,width,height)32        {33            pop=new Popup({ contentType:4,isReloadOnClose:false,width:width,height:height});34            pop.setContent("title",title);35            pop.setContent("alertCon",alertCon);36            pop.build();37            pop.show();38        }39        function ShowCallBack(para)40        {41            var o_pop = para["obj"];42            eval(para["id"]+"(true)");43            o_pop.close();44            45        }46        function ClosePop(para)47        {48        	eval(para["id"]+"(false)");49	        pop.close();50	        51	        
...jquery.pop.js
Source:jquery.pop.js  
1//2//  pop! for jQuery3//  v0.2 requires jQuery v1.2 or later4//  5//  Licensed under the MIT:6//  http://www.opensource.org/licenses/mit-license.php7//  8//  Copyright 2007,2008 SEAOFCLOUDS [http://seaofclouds.com]9//10(function($) {11  12  $.pop = function(options){13    14    // settings15    var settings = {16     pop_class : '.pop',17     pop_toggle_text : ''18    }19    20    // inject html wrapper21    function initpops (){22      $(settings.pop_class).each(function() {23        var pop_classes = $(this).attr("class");24        $(this).addClass("pop_menu");25        $(this).wrap("<div class='"+pop_classes+"'></div>");26        $(".pop_menu").attr("class", "pop_menu");27        $(this).before(" \28          <div class='pop_toggle'>"+settings.pop_toggle_text+"</div> \29          ");30      });31    }32    initpops();33    34    // assign reverse z-indexes to each pop35    var totalpops = $(settings.pop_class).size() + 1000;36    $(settings.pop_class).each(function(i) {37     var popzindex = totalpops - i;38     $(this).css({ zIndex: popzindex });39    });40    // close pops if user clicks outside of pop41    activePop = null;42    function closeInactivePop() {43      $(settings.pop_class).each(function (i) {44        if ($(this).hasClass('active') && i!=activePop) {45          $(this).removeClass('active');46          }47      });48      return false;49    }50    $(settings.pop_class).mouseover(function() { activePop = $(settings.pop_class).index(this); });51    $(settings.pop_class).mouseout(function() { activePop = null; });52    $(document.body).click(function(){ 53     closeInactivePop();54    });55    // toggle that pop56    $(".pop_toggle").click(function(){57      $(this).parent(settings.pop_class).toggleClass("active");58    });59  }...Using AI Code Generation
1var spy = sinon.spy();2spy("foo");3spy("bar");4spy("baz");5var spy = sinon.spy();6spy("foo");7spy("bar");8spy("baz");9var stub = sinon.stub();10stub.returns(42);11var stub = sinon.stub();12stub.returns(42);13var stub = sinon.stub();14stub.returns(42);15stub.reset();16var stub = sinon.stub();17stub.returns(42);18stub.resetBehavior();19var stub = sinon.stub();20stub.returns(42);21stub.resetHistory();22var stub = sinon.stub();23stub.returns(42);24stub.reset();25var stub = sinon.stub();26stub.returns(42);27stub.reset();28console.log(stubUsing AI Code Generation
1var sinon = require('sinon');2var assert = require('assert');3var obj = {4  method: function() {5    return 'hello world';6  }7};8var spy = sinon.spy(obj, 'method');9var stub = sinon.stub(obj, 'method').returns('hello fake world');10assert(obj.method.returnValues[0] === 'hello fake worldUsing AI Code Generation
1var sinon = require('sinon');2var myObject = {3  myMethod: function () {4    console.log('Hello World');5  }6};7var spy = sinon.spy(myObject, 'myMethod');8myObject.myMethod();9var sinon = require('sinon');10var myObject = {11  myMethod: function () {12    console.log('Hello World');13  }14};15var stub = sinon.stub(myObject, 'myMethod');16myObject.myMethod();17var sinon = require('sinon');18var myObject = {19  myMethod: function () {20    console.log('Hello World');21  }22};23var mock = sinon.mock(myObject);24mock.expects('myMethod').once();25myObject.myMethod();26mock.verify();27var sinon = require('sinon');28var myObject = {29  myMethod: function () {30    console.log('Hello World');31  }32};33var mock = sinon.mock(myObject);34mock.expects('myMethod').once();35myObject.myMethod();36mock.verify();37var sinon = require('sinon');38var myObject = {39  myMethod: function () {40    console.log('Hello World');41  }42};43var mock = sinon.mock(myObject);44mock.expects('myMethod').once();45myObject.myMethod();46mock.verify();47var sinon = require('sinon');48var myObject = {49  myMethod: function () {50    console.log('Hello World');51  }52};53var mock = sinon.mock(myObject);54mock.expects('myMethod').once();55myObject.myMethod();56mock.verify();57var sinon = require('sinon');58var myObject = {59  myMethod: function () {60    console.log('Hello World');61  }62};63var mock = sinon.mock(myObject);64mock.expects('myMethod').once();65myObject.myMethod();66mock.verify();67var sinon = require('Using AI Code Generation
1var sinon = require('sinon');2var obj = {3    method: function () {4        return true;5    }6};7var spy = sinon.spy(obj, "method");8obj.method();9obj.method();10obj.method.restore();11var sinon = require('sinon');12var obj = {13    method: function () {14        return true;15    }16};17var stub = sinon.stub(obj, "method");18stub.returns(false);19obj.method.restore();20var sinon = require('sinon');21var obj = {22    method: function () {23        return true;24    }25};26var mock = sinon.mock(obj);27mock.expects("method").once();28obj.method();29mock.verify();30var sinon = require('sinon');31var server = sinon.fakeServer.create();32server.respondWith(33        { "Content-Type": "text/plain" },34);35server.respond();36server.restore();37var sinon = require('sinon');38var clock = sinon.useFakeTimers();39var callback = sinon.spy();40setTimeout(callback, 100);41clock.tick(99);42clock.tick(1);43clock.restore();44var sinon = require('sinon');45var request = new sinon.FakeXMLHttpRequest();46request.open("GET", "/test", true);47request.send();48request.respond(49    { "Content-Type": "text/plain" },50);Using AI Code Generation
1var sinon = require('sinon');2var server = require('./server');3var request = require('request');4var assert = require('assert');5describe('server', function() {6    it('should return 200', function(done) {7        var stub = sinon.stub(request, 'get', function(options, callback) {8            callback(null, {statusCode: 200}, 'OK');9        });10        server.start();11            assert.equal(response.statusCode, 200);12            stub.restore();13            done();14        });15    });16});Using AI Code Generation
1var sinon = require('sinon');2var assert = require('assert');3var test = require('./test');4var stub = sinon.stub(test, 'sample', function() {5    return 'test';6});7assert.equal(test.sample(), 'test');8stub.restore();9exports.sample = function() {10    return 'sample';11}Using AI Code Generation
1var sinon = require('sinon');2var assert = require('assert');3var array = [1,2,3,4,5];4var popped = array.pop(4);5assert(array.length === 4);6assert(popped === 4);7  throw new assert.AssertionError({8    at Object.<anonymous> (/home/username/nodejs/test.js:6:5)9    at Module._compile (module.js:456:26)10    at Object..js (module.js:474:10)11    at Module.load (module.js:356:32)12    at Function._load (module.js:312:12)13    at Array.0 (module.js:479:10)14    at EventEmitter._tickCallback (node.js:192:40)15var sinon = require('sinon');16var assert = require('assert');17var array = [1,2,3,4,5];18var popped = array.pop();19assert(array.length === 4);20assert(popped === 5);21var sinon = require('sinon');22var assert = require('assert');23var array = [1,2,3,4,5];24var popped = array.pop(5);25assert(array.length === 4);26assert(popped === 5);27var sinon = require('sinon');28var assert = require('assert');29var array = [1,2,3,4,5];30var popped = array.pop(3);31assert(array.length === 4);32assert(popped === 3);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!!
