How to use restorer method in sinon

Best JavaScript code snippet using sinon

index.test.js

Source:index.test.js Github

copy

Full Screen

1jest.mock('../util/get_window');2var getWindowModule = require('../util/get_window');3var scrollRestorer = require('../index');4describe('scroll-restorer', function() {5 beforeEach(function() {6 // Mock the window object.7 jest.spyOn(getWindowModule, 'getWindow').mockReturnValue({8 addEventListener: jest.fn(),9 document: {10 body: {11 scrollHeight: 10012 }13 },14 history: {15 replaceState: jest.fn(),16 scrollRestoration: 'foo',17 state: {18 scroll: {19 x: 0,20 y: 021 }22 }23 },24 location: 'foo',25 pageXOffset: 0,26 pageYOffset: 0,27 removeEventListener: jest.fn(),28 replaceState: jest.fn(),29 // We just invoke requestAnimationFrame functions immediately.30 requestAnimationFrame: function(fn) {31 fn();32 },33 scrollTo: jest.fn()34 });35 });36 afterEach(function() {37 getWindowModule.getWindow.mockRestore();38 });39 describe('start', function() {40 it('adds a scroll event listener', function() {41 scrollRestorer.start();42 var addEventListenerArgs = getWindowModule.getWindow().addEventListener43 .mock.calls[0];44 expect(addEventListenerArgs[0]).toBe('scroll');45 });46 it('adds a scroll event listener with passive option enabled', function() {47 scrollRestorer.start();48 var addEventListenerArgs = getWindowModule.getWindow().addEventListener49 .mock.calls[0];50 expect(addEventListenerArgs[2]).toEqual({ passive: true });51 });52 it('adds a popstate event listener when autoRestore option is omitted', function() {53 scrollRestorer.start();54 // We should have attached popstate and scroll event listeners.55 expect(56 getWindowModule.getWindow().addEventListener57 ).toHaveBeenCalledTimes(2);58 // Find the popstate addEventListener call.59 var popStateListenerCall = getWindowModule60 .getWindow()61 .addEventListener.mock.calls.filter(function(callArgs) {62 return callArgs[0] === 'popstate';63 });64 expect(popStateListenerCall.length).toBe(1);65 });66 it('does not add a popstate event listener when autoRestore option is false', function() {67 scrollRestorer.start({ autoRestore: false });68 // We should have attached only a scroll listener.69 expect(70 getWindowModule.getWindow().addEventListener71 ).toHaveBeenCalledTimes(1);72 // We should not have attached a popstate listener.73 var addEventListenerArgs = getWindowModule.getWindow().addEventListener74 .mock.calls[0];75 expect(addEventListenerArgs[0]).not.toBe('popstate');76 });77 it('sets history.scrollRestoration to manual if property exists', function() {78 expect(getWindowModule.getWindow().history.scrollRestoration).toEqual(79 'foo'80 );81 scrollRestorer.start();82 expect(getWindowModule.getWindow().history.scrollRestoration).toEqual(83 'manual'84 );85 });86 it('does not set history.scrollRestoration if property does not exists', function() {87 delete getWindowModule.getWindow().history.scrollRestoration;88 scrollRestorer.start();89 expect(getWindowModule.getWindow().history.scrollRestoration).toEqual(90 undefined91 );92 });93 });94 describe('captureScroll', function() {95 beforeEach(function() {96 jest.useFakeTimers();97 });98 afterEach(function() {99 jest.useRealTimers();100 });101 it('calls #replaceState if the saved offset values have changed', function() {102 // We're pretending that the user scrolled the window by 20px on both axes.103 getWindowModule.getWindow().pageXOffset = 20;104 getWindowModule.getWindow().pageYOffset = 20;105 scrollRestorer.start();106 var addEventListenerArgs = getWindowModule.getWindow().addEventListener107 .mock.calls[0];108 // Let's verify that this is the scroll event listener.109 expect(addEventListenerArgs[0]).toEqual('scroll');110 // Let's invoke the debounced event handler directly.111 addEventListenerArgs[1]();112 // We fake the passage of time to invoke our debounced function.113 jest.runAllTimers();114 // Assert that replaceState was invoked with the "new" scroll offset values.115 expect(116 getWindowModule.getWindow().history.replaceState117 ).toHaveBeenCalledWith(118 { scroll: { x: 20, y: 20 } },119 null,120 getWindowModule.getWindow().location121 );122 });123 it('does not call #replaceState if the saved offset values have not changed', function() {124 scrollRestorer.start();125 var addEventListenerArgs = getWindowModule.getWindow().addEventListener126 .mock.calls[0];127 // Let's verify that this is the scroll event listener.128 expect(addEventListenerArgs[0]).toEqual('scroll');129 // Let's invoke the debounced event handler directly.130 addEventListenerArgs[1]();131 // We fake the passage of time to invoke our debounced function.132 jest.runAllTimers();133 expect(134 getWindowModule.getWindow().history.replaceState135 ).not.toHaveBeenCalled();136 });137 });138 describe('getSavedScroll', function() {139 it('returns value from provided input', function() {140 expect(scrollRestorer.getSavedScroll({ state: { scroll: 'foo' } })).toBe(141 'foo'142 );143 });144 it('returns value from window.history when input is not defined', function() {145 expect(scrollRestorer.getSavedScroll()).toEqual({ x: 0, y: 0 });146 });147 it('returns undefined when input.state is undefined', function() {148 expect(scrollRestorer.getSavedScroll({ foo: 'bar' })).toEqual(undefined);149 });150 });151 describe('restoreScroll', function() {152 it('calls #scrollTo with a position retrieved from state in window.history', function() {153 // We're pretending that a scroll position has been saved previously.154 getWindowModule.getWindow().history.state.scroll = { x: 0, y: 20 };155 scrollRestorer.restoreScroll();156 expect(getWindowModule.getWindow().scrollTo).toHaveBeenCalledWith(0, 20);157 });158 it('calls #scrollTo with a position retrieved from a popstate event', function() {159 var popstateEvent = { state: { scroll: { x: 0, y: 40 } } };160 scrollRestorer.restoreScroll(popstateEvent);161 expect(getWindowModule.getWindow().scrollTo).toHaveBeenCalledWith(0, 40);162 });163 it('does not call #scrollTo when unnecessary', function() {164 // We're pretending that the user scrolled the window by 20px on the y axis.165 getWindowModule.getWindow().pageXOffset = 0;166 getWindowModule.getWindow().pageYOffset = 20;167 // We're pretending that the same scroll position has already been saved.168 getWindowModule.getWindow().history.state.scroll = { x: 0, y: 20 };169 scrollRestorer.start();170 scrollRestorer.restoreScroll();171 scrollRestorer.end();172 expect(getWindowModule.getWindow().scrollTo).not.toHaveBeenCalled();173 });174 it('returns early if no saved scroll positions exist', function() {175 getWindowModule.getWindow().requestAnimationFrame = jest.fn();176 scrollRestorer.restoreScroll({ foo: 'bar' });177 expect(178 getWindowModule.getWindow().requestAnimationFrame179 ).not.toHaveBeenCalled();180 });181 });182 describe('end', function() {183 it('removes the scroll event listener with identical arguments', function() {184 scrollRestorer.start();185 scrollRestorer.end();186 var addEventListenerArgs = getWindowModule.getWindow().addEventListener187 .mock.calls[0];188 var removeEventListenerArgs = getWindowModule.getWindow()189 .removeEventListener.mock.calls[0];190 // Let's verify that this is the scroll event listener.191 expect(addEventListenerArgs[0]).toEqual('scroll');192 // Let's verify that our handler function is === when adding and removing.193 expect(addEventListenerArgs[1]).toBe(removeEventListenerArgs[1]);194 expect(addEventListenerArgs).toEqual(removeEventListenerArgs);195 });196 it('removes the popstate event listener with identical arguments', function() {197 scrollRestorer.start({ autoRestore: true });198 scrollRestorer.end();199 var addEventListenerArgs = getWindowModule.getWindow().addEventListener200 .mock.calls[1];201 var removeEventListenerArgs = getWindowModule.getWindow()202 .removeEventListener.mock.calls[1];203 // Let's verify that this is the popstate event listener.204 expect(addEventListenerArgs[0]).toEqual('popstate');205 // Let's verify that our handler function is === when adding and removing.206 expect(addEventListenerArgs[1]).toBe(removeEventListenerArgs[1]);207 expect(addEventListenerArgs).toEqual(removeEventListenerArgs);208 });209 });...

Full Screen

Full Screen

ExifRestorer.js

Source:ExifRestorer.js Github

copy

Full Screen

1//Based on MinifyJpeg2//http://elicon.blog57.fc2.com/blog-entry-206.html3qq.ExifRestorer = (function()4{5 6 var ExifRestorer = {};7 8 ExifRestorer.KEY_STR = "ABCDEFGHIJKLMNOP" +9 "QRSTUVWXYZabcdef" +10 "ghijklmnopqrstuv" +11 "wxyz0123456789+/" +12 "=";13 ExifRestorer.encode64 = function(input)14 {15 var output = "",16 chr1, chr2, chr3 = "",17 enc1, enc2, enc3, enc4 = "",18 i = 0;19 do {20 chr1 = input[i++];21 chr2 = input[i++];22 chr3 = input[i++];23 enc1 = chr1 >> 2;24 enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);25 enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);26 enc4 = chr3 & 63;27 if (isNaN(chr2)) {28 enc3 = enc4 = 64;29 } else if (isNaN(chr3)) {30 enc4 = 64;31 }32 output = output +33 this.KEY_STR.charAt(enc1) +34 this.KEY_STR.charAt(enc2) +35 this.KEY_STR.charAt(enc3) +36 this.KEY_STR.charAt(enc4);37 chr1 = chr2 = chr3 = "";38 enc1 = enc2 = enc3 = enc4 = "";39 } while (i < input.length);40 return output;41 };42 43 ExifRestorer.restore = function(origFileBase64, resizedFileBase64)44 {45 var expectedBase64Header = "data:image/jpeg;base64,";46 if (!origFileBase64.match(expectedBase64Header))47 {48 return resizedFileBase64;49 } 50 51 var rawImage = this.decode64(origFileBase64.replace(expectedBase64Header, ""));52 var segments = this.slice2Segments(rawImage);53 54 var image = this.exifManipulation(resizedFileBase64, segments);55 56 return expectedBase64Header + this.encode64(image);57 58 };59 ExifRestorer.exifManipulation = function(resizedFileBase64, segments)60 {61 var exifArray = this.getExifArray(segments),62 newImageArray = this.insertExif(resizedFileBase64, exifArray),63 aBuffer = new Uint8Array(newImageArray);64 return aBuffer;65 };66 ExifRestorer.getExifArray = function(segments)67 {68 var seg;69 for (var x = 0; x < segments.length; x++)70 {71 seg = segments[x];72 if (seg[0] == 255 & seg[1] == 225) //(ff e1)73 {74 return seg;75 }76 }77 return [];78 };79 ExifRestorer.insertExif = function(resizedFileBase64, exifArray)80 {81 var imageData = resizedFileBase64.replace("data:image/jpeg;base64,", ""),82 buf = this.decode64(imageData),83 separatePoint = buf.indexOf(255,3),84 mae = buf.slice(0, separatePoint),85 ato = buf.slice(separatePoint),86 array = mae;87 array = array.concat(exifArray);88 array = array.concat(ato);89 return array;90 };91 92 ExifRestorer.slice2Segments = function(rawImageArray)93 {94 var head = 0,95 segments = [];96 while (1)97 {98 if (rawImageArray[head] == 255 & rawImageArray[head + 1] == 218){break;}99 if (rawImageArray[head] == 255 & rawImageArray[head + 1] == 216)100 {101 head += 2;102 }103 else104 {105 var length = rawImageArray[head + 2] * 256 + rawImageArray[head + 3],106 endPoint = head + length + 2,107 seg = rawImageArray.slice(head, endPoint);108 segments.push(seg);109 head = endPoint;110 }111 if (head > rawImageArray.length){break;}112 }113 return segments;114 };115 116 ExifRestorer.decode64 = function(input) 117 {118 var output = "",119 chr1, chr2, chr3 = "",120 enc1, enc2, enc3, enc4 = "",121 i = 0,122 buf = [];123 // remove all characters that are not A-Z, a-z, 0-9, +, /, or =124 var base64test = /[^A-Za-z0-9\+\/\=]/g;125 if (base64test.exec(input)) {126 throw new Error("There were invalid base64 characters in the input text. " +127 "Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='");128 }129 input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");130 do {131 enc1 = this.KEY_STR.indexOf(input.charAt(i++));132 enc2 = this.KEY_STR.indexOf(input.charAt(i++));133 enc3 = this.KEY_STR.indexOf(input.charAt(i++));134 enc4 = this.KEY_STR.indexOf(input.charAt(i++));135 chr1 = (enc1 << 2) | (enc2 >> 4);136 chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);137 chr3 = ((enc3 & 3) << 6) | enc4;138 buf.push(chr1);139 if (enc3 != 64) {140 buf.push(chr2);141 }142 if (enc4 != 64) {143 buf.push(chr3);144 }145 chr1 = chr2 = chr3 = "";146 enc1 = enc2 = enc3 = enc4 = "";147 } while (i < input.length);148 return buf;149 };150 151 return ExifRestorer;...

Full Screen

Full Screen

restorer.js

Source:restorer.js Github

copy

Full Screen

1"use strict";2/*3This file is part of the ONLINE WARBAND CREATOR (https://github.com/suppenhuhn79/sbhowc)4Copyright 2021 Christoph Zager5Licensed unter the GNU Affero General Public License, Version 36See the full license text at https://www.gnu.org/licenses/agpl-3.0.en.html7 */8var restorer = {};9restorer.sort =10{11 field: "last-modified",12 direction: 113};14restorer.show = function ()15{16 owc.ui.showBluebox(document.getElementById("restorer"));17 restorer.listStoredData();18};19restorer.close = () => owc.ui.sweepVolatiles();20restorer.getSelectedPid = function ()21{22 let selectedItem = document.getElementById("restorer-table-frame").querySelector(".selected");23 return (!!selectedItem) ? selectedItem.getAttribute("data-id") : null;24};25restorer.storageItemClick = function (clickEvent)26{27 let selectedItem = document.getElementById("restorer-table-frame").querySelector(".selected");28 if (!!selectedItem)29 {30 selectedItem.classList.remove("selected");31 };32 clickEvent.target.closest("tr[data-id]").classList.add("selected");33};34restorer.restoreClick = function (clickEvent)35{36 let selectedPid = restorer.getSelectedPid();37 if (!!selectedPid)38 {39 restorer.close();40 let warbandCode = JSON.parse(localStorage.getItem(selectedPid)).data;41 owc.importWarband(warbandCode);42 /* unselect everything in document, some browsers interpret a dblclk as intend to select anything */43 if (typeof window.getSelection === "function")44 {45 window.getSelection().removeAllRanges();46 }47 else if (typeof document.selection === "funtion")48 {49 document.selection.empty();50 };51 };52};53restorer.discardClick = function (clickEvent)54{55 clickEvent.stopPropagation();56 let selectedPid = restorer.getSelectedPid();57 if (!!selectedPid)58 {59 localStorage.removeItem(selectedPid);60 let deletedBubble = document.getElementById("deletedBubble");61 deletedBubble.style.left = Math.floor(document.querySelector("#restorer input[value=\"discard\"]").getBoundingClientRect().x - document.getElementById("restorer").getBoundingClientRect().x) + "px";62 owc.ui.showNotification(deletedBubble);63 restorer.listStoredData();64 };65};66restorer.tableheaderClick = function (clickEvent)67{68 let sortField = clickEvent.target.getAttribute("data-sortfield");69 if (restorer.sort.field === sortField)70 {71 restorer.sort.direction = restorer.sort.direction * -1;72 }73 else74 {75 restorer.sort.field = sortField;76 restorer.sort.direction = 1;77 };78 restorer.listStoredData();79};80restorer.listStoredData = function ()81{82 function _naturalPast(pastDate)83 {84 const wordings = ["just now", "{{n}} minutes ago", "{{6}} hours ago"];85 const dayWordings = ["today", "yesterday", "two days ago"];86 let result = "";87 let now = new Date();88 let maxHours = Number(/\{{2}(\d+)\}{2}/.exec(wordings[2])[1]);89 let secondsDiff = (now.getTime() - pastDate.getTime()) / 1000;90 let diff =91 {92 minutes: secondsDiff / 60,93 hours: secondsDiff / 60 / 60,94 days: Math.floor((Date.UTC(now.getFullYear(), now.getMonth(), now.getDate()) - Date.UTC(pastDate.getFullYear(), pastDate.getMonth(), pastDate.getDate())) / (1000 * 60 * 60 * 24))95 };96 if (secondsDiff < 60)97 {98 result = wordings[0];99 }100 else if (diff.minutes < 60)101 {102 result = wordings[1].replace(/\{{2}.\}{2}/, Math.floor(diff.minutes));103 }104 else if (diff.hours < maxHours)105 {106 result = wordings[2].replace(/\{{2}.\}{2}/, Math.floor(diff.hours));107 }108 else if (diff.days < dayWordings.length)109 {110 result = dayWordings[diff.days] + " " + pastDate.toIsoFormatText("HN");111 }112 else113 {114 result = pastDate.toIsoFormatText();115 };116 return result;117 };118 function _getLocalStorageData()119 {120 let result = [];121 for (let key in localStorage)122 {123 if (/^(?=\D*\d)[\d\w]{6}$/.test(key) === true)124 {125 let storedData = JSON.parse(localStorage[key]);126 let lastModifiedDate = new Date().fromIsoString(storedData.date);127 result.push(128 {129 pid: key,130 'warband-name': storedData.title,131 'figure-count': storedData["figure-count"],132 points: storedData.points,133 'last-modified': lastModifiedDate,134 'last-modified-text': _naturalPast(lastModifiedDate)135 }136 );137 };138 };139 switch (restorer.sort.field)140 {141 case "warband-name":142 result.sort((a, b) => (a["warband-name"].localeCompare(b["warband-name"]) * restorer.sort.direction));143 break;144 default:145 result.sort((a, b) => (((a[restorer.sort.field] < b[restorer.sort.field]) ? 1 : -1) * restorer.sort.direction));146 };147 return result;148 };149 let refNode = document.getElementById("restorer-table-frame");150 let variables =151 {152 'cached-warbands': _getLocalStorageData()153 };154 const thresholdWidth = 400;155 let snippetName = (Number(document.body.clientWidth) <= thresholdWidth) ? "table-frame-small" : "table-frame-normal";156 owc.ui.setElementContent(refNode, pageSnippets.restorer[snippetName].produce(restorer, variables));...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var assert = require('assert');3var myObj = {4 myMethod: function () {5 console.log('myMethod was called');6 }7};8var spy = sinon.spy(myObj, 'myMethod');9myObj.myMethod();10assert(spy.called);11spy.restore();12myObj.myMethod();13assert(!spy.called);

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var obj = {3 method: function () {}4};5var spy = sinon.spy(obj, "method");6obj.method(42);7obj.method.restore();8obj.method(42);

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var chai = require('chai');3var expect = chai.expect;4describe('Restorer', function () {5 it('should restore the stubbed method', function () {6 var stub = sinon.stub(console, 'log');7 console.log('hello');8 expect(stub.calledOnce).to.be.true;9 stub.restore();10 console.log('hello');11 expect(stub.calledTwice).to.be.false;12 });13});14var sinon = require('sinon');15var chai = require('chai');16var expect = chai.expect;17describe('Restorer', function () {18 it('should restore the stubbed method', function () {19 var stub = sinon.stub(console, 'log');20 console.log('hello');21 expect(stub.calledOnce).to.be.true;22 stub.restore();23 console.log('hello');24 expect(stub.calledTwice).to.be.false;25 });26});27var sinon = require('sinon');28var chai = require('chai');29var expect = chai.expect;30describe('Restorer', function () {31 it('should restore the stubbed method', function () {32 var stub = sinon.stub(console, 'log');33 console.log('hello');34 expect(stub.calledOnce).to.be.true;35 stub.restore();36 console.log('hello');37 expect(stub.calledTwice).to.be.false;38 });39});40var sinon = require('sinon');41var chai = require('chai');42var expect = chai.expect;43describe('Restorer', function () {44 it('should restore the stubbed method', function () {45 var stub = sinon.stub(console, 'log');46 console.log('hello');47 expect(stub.calledOnce).to.be.true;48 stub.restore();49 console.log('hello');50 expect(stub.calledTwice).to.be.false;51 });52});53var sinon = require('sinon');54var chai = require('chai');55var expect = chai.expect;56describe('Restorer', function () {57 it('should restore the stubbed method', function () {58 var stub = sinon.stub(console, 'log');59 console.log('

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var assert = require('assert');3var myObj = {4 method: function () {5 console.log("Method called");6 }7};8var stub = sinon.stub(myObj, "method");9stub();10stub.restore();11stub();12var sinon = require('sinon');13var assert = require('assert');14var myObj = {15 method: function () {16 console.log("Method called");17 }18};19var stub = sinon.stub(myObj, "method");20stub();21stub.restore();22stub();23var sinon = require('sinon');24var assert = require('assert');25var myObj = {26 method: function () {27 console.log("Method called");28 }29};30var stub = sinon.stub(myObj, "method");31stub();32stub.restore();33stub();34var sinon = require('sinon');35var assert = require('assert');36var myObj = {37 method: function () {38 console.log("Method called");39 }40};41var stub = sinon.stub(myObj, "method");42stub();43stub.restore();44stub();45var sinon = require('sinon');46var assert = require('assert');47var myObj = {48 method: function () {49 console.log("Method called");50 }51};52var stub = sinon.stub(myObj, "method");53stub();54stub.restore();55stub();56var sinon = require('sinon');57var assert = require('assert');58var myObj = {59 method: function () {60 console.log("Method called");61 }62};63var stub = sinon.stub(myObj, "method");64stub();65stub.restore();66stub();67var sinon = require('sinon');68var assert = require('assert');69var myObj = {70 method: function ()

Full Screen

Using AI Code Generation

copy

Full Screen

1const sinon = require('sinon');2const fs = require('fs');3const readFile = sinon.stub(fs, 'readFile');4readFile.withArgs('hello.txt').yields(null, 'Hello');5readFile.withArgs('goodbye.txt').yields(null, 'Goodbye');6sinon.fake.restore();7const sinon = require('sinon');8const fs = require('fs');9const readFile = sinon.stub(fs, 'readFile');10readFile.withArgs('hello.txt').yields(null, 'Hello');11readFile.withArgs('goodbye.txt').yields(null, 'Goodbye');12sinon.fake.restore();13const sinon = require('sinon');14const fs = require('fs');15const readFile = sinon.stub(fs, 'readFile');16readFile.withArgs('hello.txt').yields(null, 'Hello');17readFile.withArgs('goodbye.txt').yields(null, 'Goodbye');18sinon.fake.restore();19const sinon = require('sinon');20const fs = require('fs');21const readFile = sinon.stub(fs, 'readFile');22readFile.withArgs('hello.txt').yields(null, 'Hello');23readFile.withArgs('goodbye.txt').yields(null, 'Goodbye');24sinon.fake.restore();25const sinon = require('sinon');26const fs = require('fs');27const readFile = sinon.stub(fs, 'readFile');28readFile.withArgs('hello.txt').yields(null, 'Hello');29readFile.withArgs('goodbye.txt').yields(null, 'Goodbye');30sinon.fake.restore();31const sinon = require('sinon');32const fs = require('fs');33const readFile = sinon.stub(fs, 'readFile');

Full Screen

Using AI Code Generation

copy

Full Screen

1const sinon = require('sinon');2const assert = require('assert');3const {getUsers} = require('./user');4describe('getUsers', () => {5 it('should return users', () => {6 const stub = sinon.stub().returns([1, 2, 3]);7 const users = getUsers(stub);8 assert.deepEqual(users, [1, 2, 3]);9 });10 it('should call callback', () => {11 const stub = sinon.stub().returns([1, 2, 3]);12 getUsers(stub);13 assert(stub.calledOnce);14 });15});

Full Screen

Using AI Code Generation

copy

Full Screen

1const sinon = require('sinon');2const assert = require('assert');3const { EventEmitter } = require('events');4const { once } = require('events');5const emitter = new EventEmitter();6const stub = sinon.stub().resolves(42);7emitter.on('foo', stub);8emitter.emit('foo', 'bar');9assert(stub.calledOnceWith('bar'));10const sinon = require('sinon');11const assert = require('assert');12const { EventEmitter } = require('events');13const { once } = require('events');14const emitter = new EventEmitter();15const stub = sinon.stub().resolves(42);16emitter.on('foo', stub);17emitter.emit('foo', 'bar');18assert(stub.calledOnceWith('bar'));19stub.restore();

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run sinon automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful