Best JavaScript code snippet using sinon
ArraySpecs.js
Source:ArraySpecs.js  
...10///////////////////////////////////////11describe("purge", function() {12	function testPurge(original, expected, filterFn) {13		purge(original, filterFn);14		specs.arrayEquals(original, expected);15	}16	it("removes elements from the array that match the given filter callback", function() {17		testPurge([4, 6, 2, 6, 7, 2], [4, 2, 2], function(item) {18			return item >= 6;19		});20	});21	it("uses removeAt if exists", function() {22		var arr = [4, 6, 2, 6, 7, 2];23		var removeAtCalls = 0;24		arr.removeAt = function(idx) {25			removeAtCalls++;26			removeAt(this, idx);27		};28		testPurge(arr, [4, 2, 2], function(item) {29			return item >= 6;30		});31		expect(removeAtCalls).toBe(3);32	});33	it("returns the indices where items where removed from the original array", function() {34		specs.arrayEquals(purge([parseInt("x"), parseInt("y"), 6, 7, parseInt("z"), 2], isNaN), [0, 1, 4]);35	});36	it("returns nothing if no items are removed", function() {37		expect(purge([4, 6, 2, 6, 7, 2], isNaN)).toEqual(undefined);38	});39});40describe("contains", function () {41	it("returns true if an element exists in the array", function () {42		var arr = ["A", "B", "C"];43		expect(contains(arr, "B")).toBe(true);44		expect(arr.contains("B")).toBe(true);45	});46	it("returns false if an element does not exist in the array", function () {47		var arr = ["A", "B", "C"];48		expect(contains(arr, "D")).toBe(false);49		expect(arr.contains("D")).toBe(false);50	});51});52describe("distinct", function () {53	it("removes duplicates from a list", function() {54		specs.arrayEquals(distinct([0, 1, 4, 1, 5]), [0, 1, 4, 5]);55	});56	it("removes multiple duplicates", function() {57		specs.arrayEquals(distinct([0, 1, 4, 1, 4, 5]), [0, 1, 4, 5]);58		specs.arrayEquals(distinct([0, 1, 5, 4, 1, 4, 5]), [0, 1, 5, 4]);59	});60	61	it("removes back-to-back duplicates", function() {62		specs.arrayEquals(distinct([0, 0, 1, 4, 1, 4, 5]), [0, 1, 4, 5]);63	});64	65	it("preserves first encountered item", function() {66		specs.arrayEquals(distinct([0, 1, 0, 1, 4, 1, 4, 5]), [0, 1, 4, 5]);67	});68});69describe("intersect", function() {70	it("produces the set intersection of two arrays, using strict equality", function() {71		specs.arrayEquals(intersect([], []), [], true);72		specs.arrayEquals(intersect([0, 1], [1, 2]), [1], true);73		specs.arrayEquals(intersect([0, 1, 2, 3, 4], [4, 3, 2, 1]), [3, 1, 4, 2], true);74	});75	76	it("returns distinct results", function() {77		specs.arrayEquals(intersect([0, 1], [1, 2]), [1], true);78		specs.arrayEquals(intersect([0, 1, 2, 4, 3, 4, 1], [4, 3, 2, 1]), [3, 1, 4, 2], true);79	});80});81describe("first", function() {82	it("returns the first item in the list that passes the given filter", function() {83		var arr = [0, 54, 23, 5];84		expect(first(arr, function(i) { return i > 5; })).toBe(54);85		expect(first(arr, function(i) { return i > 54; })).toBe(null);86		expect(first(arr, function(i) { return i > 0 && i < 10; })).toBe(5);87		expect(first(arr)).toBe(0);88		expect(arr.first(function(i) { return i > 5; })).toBe(54);89		expect(arr.first(function(i) { return i > 54; })).toBe(null);90		expect(arr.first(function(i) { return i > 0 && i < 10; })).toBe(5);91		expect(arr.first()).toBe(0);92	});93});94describe("map", function () {95	it("maps items in the array using the callback function provided", function () {96		specs.arrayEquals(map(["A", "B", "C"], function (item, index) {97			return item.toLowerCase();98		}), ["a", "b", "c"], true);99	});100});101describe("indexOf", function () {102	it("returns the index of a given element in the array", function () {103		var arr = ["A", "B", "C"];104		expect(indexOf(arr, "B")).toBe(1);105		expect(arr.indexOf("B")).toBe(1);106	});107});108describe("lastIndexOf", function () {109	it("returns the last index of a given element in the array", function () {110		var arr = ["A", "B", "C", "A"];111		expect(lastIndexOf(arr, "A")).toBe(3);112	});113});114describe("fill", function () {115	it("pushes a given number of items into the array with the given value", function () {116		var arr = ["A", "B", "C"];117		arr.fill("D", 3);118		expect(arr[3]).toBe("D");119		expect(arr[4]).toBe("D");120		expect(arr[5]).toBe("D");121		expect(arr[6]).toBe(undefined);122	});123});124describe("reduce", function () {125	it("accumulates values in the array into a single value", function () {126		var arr = [5, 2, 3, -4];127		var total = reduce(arr, function(previousValue, currentValue, index, array) {128			return previousValue + currentValue;129		});130		expect(total).toBe(6);131		total = reduce(arr, function(previousValue, currentValue, index, array) {132			return previousValue + currentValue;133		}, 0);134		expect(total).toBe(6);135	});136});137describe("filter", function () {138	it("copies elements of the source array that pass the given filter function", function () {139		var arr = [5, 2, 3, -4, 0];140		specs.arrayEquals(filter(arr, function(i) { return i >= 0; }), [5, 2, 3, 0]);141	});142	it("filter function result can be truthy", function () {143		var arr = [5, 2, 3, -4, 0];144		specs.arrayEquals(filter(arr, function(i) { return i; }), [5, 2, 3, -4]);145	});146});147describe("single", function () {148	it("returns the single item in the array if no filter function is specified", function () {149		var arr = [5];150		expect(single(arr)).toBe(5);151	});152	it("returns a single item from the array that matches the given filter function", function () {153		var arr = [5, 2, 3, -4, 0];154		expect(single(arr, function(i) { return i < 0; })).toBe(-4);155	});156	it("throws an error if more than one item matches the given filter function", function () {157		var arr = [5, 2, 3, -4, 0];158		expect(function() {159			single(arr, function(i) { return i <= 0; });160		}).toThrow("Expected a single item, but found 2.");161	});162	it("throws an error if there are no items and no filter function is specified", function () {163		var arr = [5, 2, 3, -4, 0];164		expect(function () {165			single(arr, function (i) { return i < -4; });166		}).toThrow("Expected a single item, but did not find a match.");167	});168	it("throws an error if no items match the given filter function", function () {169		var arr = [];170		expect(function() {171			single(arr);172		}).toThrow("Expected a single item, but did not find a match.");173	});174});175describe("last", function() {176	it("returns the last item in the list that passes the given filter", function() {177		var arr = [0, 54, 23, 5];178		expect(last(arr, function(i) { return i > 5; })).toBe(23);179		expect(last(arr, function(i) { return i > 54; })).toBe(null);180		expect(last(arr, function(i) { return i > 0 && i < 10; })).toBe(5);181		expect(last(arr, function(i) { return i < 10; })).toBe(5);182		expect(last(arr)).toBe(5);183		expect(arr.last(function(i) { return i > 5; })).toBe(23);184		expect(arr.last(function(i) { return i > 54; })).toBe(null);185		expect(arr.last(function(i) { return i > 0 && i < 10; })).toBe(5);186		expect(arr.last(function(i) { return i < 10; })).toBe(5);187		expect(arr.last()).toBe(5);188	});189});190describe("remove", function() {191	it("removes a single item from an array", function() {192		var target = [0, 1, 2];193		remove(target, 1);194		specs.arrayEquals(target, [0, 2]);195	});196});197describe("removeAt", function() {198	it("removes a single item from an array at the given index", function() {199		var target = [0, 1, 2];200		removeAt(target, 0);201		specs.arrayEquals(target, [1, 2]);202	});203});204describe("removeRange", function() {205	it("removes a number of items from an array at the given index", function() {206		var target = [0, 1, 2, 3, 4];207		removeRange(target, 2, 2);208		specs.arrayEquals(target, [0, 1, 4]);209	});210});211describe("insert", function() {212	it("adds a single item to an array at the given index", function() {213		var target = [0, 1, 2];214		insert(target, 1, 0.5);215		specs.arrayEquals(target, [0, 0.5, 1, 2]);216	});217});218describe("insertRange", function() {219	it("adds a number of items to an array at the given index", function() {220		var target = [0, 1, 2];221		insertRange(target, 1, [0.5, 0.75, 0.9]);222		specs.arrayEquals(target, [0, 0.5, 0.75, 0.9, 1, 2]);223	});224});225describe("update", function() {226	var spies = {227		insert: function(index, item) { return insert(this, index, item); },228		insertRange: function(index, items) { return insertRange(this, index, items); },229		removeAt: function(index) { return removeAt(this, index); },230		removeRange: function(index, count) { return removeRange(this, index, count); }231	};232	it("turns a single added item into an insert", function() {233		var source = [0, 1, 2, 3];234		var target = [0, 1, 2, 3, 4];235		var insert = jasmine.spyOn(spies, "insert").andCallThrough();236		source.insert = insert;237		update(source, target);238		specs.arrayEquals(source, target);239		expect(insert).toHaveBeenCalledWith(4, 4);240		241		source = [0, 1, 3, 4];242		source.insert = insert;243		update(source, target);244		specs.arrayEquals(source, target);245		expect(insert).toHaveBeenCalledWith(2, 2);246		source = [1, 2, 3, 4];247		source.insert = insert;248		update(source, target);249		specs.arrayEquals(source, target);250		expect(insert).toHaveBeenCalledWith(0, 0);251	});252	it("turns multiple added items into a single insertRange", function() {253		var source = [2, 3, 4];254		var target = [0, 1, 2, 3, 4];255		var insertRange = jasmine.spyOn(spies, "insertRange").andCallThrough();256		source.insertRange = insertRange;257		update(source, target);258		specs.arrayEquals(source, target);259		expect(insertRange).toHaveBeenCalledWith(0, [0, 1]);260		source = [0, 1, 4];261		source.insertRange = insertRange;262		update(source, target);263		specs.arrayEquals(source, target);264		expect(insertRange).toHaveBeenCalledWith(2, [2, 3]);265		source = [0, 1, 2];266		source.insertRange = insertRange;267		update(source, target);268		specs.arrayEquals(source, target);269		expect(insertRange).toHaveBeenCalledWith(3, [3, 4]);270	});271	it("turns a single removed item into a removeAt", function() {272		var source = [0, 1, 2, 3, 4];273		var target = [1, 2, 3, 4];274		var removeAt = jasmine.spyOn(spies, "removeAt").andCallThrough();275		source.removeAt = removeAt;276		update(source, target);277		specs.arrayEquals(source, target);278		expect(removeAt).toHaveBeenCalledWith(0);279		source = [0, 1, 2, 3, 4];280		source.removeAt = removeAt;281		target = [0, 1, 2, 3];282		update(source, target);283		specs.arrayEquals(source, target);284		expect(removeAt).toHaveBeenCalledWith(4);285		source = [0, 1, 2, 3, 4];286		source.removeAt = removeAt;287		target = [0, 1, 3, 4];288		update(source, target);289		specs.arrayEquals(source, target);290		expect(removeAt).toHaveBeenCalledWith(2);291	});292	it("turns multiple removed items into a removeRange", function() {293		var source = [0, 1, 2, 3, 4];294		var target = [2, 3, 4];295		var removeRange = jasmine.spyOn(spies, "removeRange").andCallThrough();296		source.removeRange = removeRange;297		update(source, target);298		specs.arrayEquals(source, target);299		expect(removeRange).toHaveBeenCalledWith(0, 2);300		source = [0, 1, 2, 3, 4];301		source.removeRange = removeRange;302		target = [0, 1, 2];303		update(source, target);304		specs.arrayEquals(source, target);305		expect(removeRange).toHaveBeenCalledWith(3, 2);306		source = [0, 1, 2, 3, 4];307		source.removeRange = removeRange;308		target = [0, 1, 4];309		update(source, target);310		specs.arrayEquals(source, target);311		expect(removeRange).toHaveBeenCalledWith(2, 2);312	});313	it("turns a changed item into a removeAt and insert", function() {314		var source = [0, 1, 2];315		var target = [0, 1, 3];316		var removeAt = jasmine.spyOn(spies, "removeAt").andCallThrough();317		source.removeAt = removeAt;318		var insert = jasmine.spyOn(spies, "insert").andCallThrough();319		source.insert = insert;320		update(source, target);321		specs.arrayEquals(source, target);322		expect(removeAt).toHaveBeenCalledWith(2);323		expect(insert).toHaveBeenCalledWith(2, 3);324		source = [0, 1, 2];325		target = [-1, 1, 2];326		source.removeAt = removeAt;327		source.insert = insert;328		update(source, target);329		specs.arrayEquals(source, target);330		expect(removeAt).toHaveBeenCalledWith(0);331		expect(insert).toHaveBeenCalledWith(0, -1);332	});333	it("turns a swap into an add and a remove", function() {334		var source = [6, 4];335		var target = [4, 6];336		update(source, target);337		specs.arrayEquals(source, target);338	});339	it("turns entirely unmatched arrays into a removeRange and insertRange", function() {340		var source = [0, 1, 2, 3];341		var target = [4, 5, 6];342		var removeRange = jasmine.spyOn(spies, "removeRange").andCallThrough();343		source.removeRange = removeRange;344		var insertRange = jasmine.spyOn(spies, "insertRange").andCallThrough();345		source.insertRange = insertRange;346		update(source, target);347		specs.arrayEquals(source, target);348		expect(removeRange).toHaveBeenCalledWith(0, 4);349		expect(insertRange).toHaveBeenCalledWith(0, [4, 5, 6]);350	});351	it("handles miscellaneous combinations of add and remove in arrays with varying degrees of divergences", function() {352		var source = [6, 7, 8, 2, 4, 6];353		var target = [4, 6, 7, 8];354		update(source, target);355		specs.arrayEquals(source, target);356		source = [6, 2, 4];357		target = [4, 6];358		update(source, target);359		specs.arrayEquals(source, target);360		source = [1, 7, 5, 6];361		target = [1, 2, 3, 4, 5, 6];362		update(source, target);363		specs.arrayEquals(source, target);364		source = [0, 1, 5, 6];365		target = [1, 2, 3, 4, 5, 6];366		update(source, target);367		specs.arrayEquals(source, target);368	});369});370// Run Tests371///////////////////////////////////////372jasmine.jasmine.getEnv().addReporter(new jasmineConsole.Reporter());...historicalscheduler.js
Source:historicalscheduler.js  
...3  /* jshint undef: true, unused: true */4  /* globals QUnit, test, Rx, equal, ok */5  QUnit.module('HistoricalScheduler');6  var HistoricalScheduler = Rx.HistoricalScheduler;7  function arrayEquals(first, second) {8    if (first.length !== second.length) {9      ok(false);10    }11    for (var i = 0, len = first.length; i < len; i++) {12      var f = first[i], s = second[i];13      if (f.equals && s.equals) {14        ok(f.equals(s));15      } else {16        ok(f === s);17      }18    }19  }20  function time(days) {21    var d = new Date(1979,10,31,4,30,15);22    d.setUTCDate(d.getDate() + days);23    return d.getTime();24  }25  function fromDays(days) {26    return 86400000 * days;27  }28  function Timestamped (value, timestamp) {29    this.value = value;30    this.timestamp = timestamp;31  }32  Timestamped.prototype.equals = function (other) {33    if (other == null) { return false; }34    return other.value === this.value && other.timestamp === this.timestamp;35  };36  test('constructor', function () {37    var s = new HistoricalScheduler();38    equal(0, s.clock);39    equal(false, s.isEnabled);40  });41  test('start and stop', function () {42    var s = new HistoricalScheduler();43    var list = [];44    s.scheduleAbsolute(null, time(0), function () { list.push(new Timestamped(1, s.now())); });45    s.scheduleAbsolute(null, time(1), function () { list.push(new Timestamped(2, s.now())); });46    s.scheduleAbsolute(null, time(2), function () { s.stop(); });47    s.scheduleAbsolute(null, time(3), function () { list.push(new Timestamped(3, s.now())); });48    s.scheduleAbsolute(null, time(4), function () { s.stop(); });49    s.scheduleAbsolute(null, time(5), function () { s.start(); });50    s.scheduleAbsolute(null, time(6), function () { list.push(new Timestamped(4, s.now())); });51    s.start();52    equal(time(2), s.now());53    equal(time(2), s.clock);54    s.start();55    equal(time(4), s.now());56    equal(time(4), s.clock);57    s.start();58    equal(time(6), s.now());59    equal(time(6), s.clock);60    s.start();61    equal(time(6), s.now());62    equal(time(6), s.clock);63    arrayEquals(list, [64      new Timestamped(1, time(0)),65      new Timestamped(2, time(1)),66      new Timestamped(3, time(3)),67      new Timestamped(4, time(6))68    ]);69  });70  test('order', function () {71    var s = new HistoricalScheduler();72    var list = [];73    s.scheduleAbsolute(null, time(2), function () { list.push(new Timestamped(2, s.now())); });74    s.scheduleAbsolute(null, time(3), function () { list.push(new Timestamped(3, s.now())); });75    s.scheduleAbsolute(null, time(1), function () { list.push(new Timestamped(0, s.now())); });76    s.scheduleAbsolute(null, time(1), function () { list.push(new Timestamped(1, s.now())); });77    s.start();78    arrayEquals(list, [79      new Timestamped(0, time(1)),80      new Timestamped(1, time(1)),81      new Timestamped(2, time(2)),82      new Timestamped(3, time(3))83    ]);84  });85  test('cancellation', function () {86    var s = new HistoricalScheduler();87    var list = [];88    var d = s.scheduleAbsolute(null, time(2), function () { list.push(new Timestamped(2, s.now())); });89    s.scheduleAbsolute(null, time(1), function () {90      list.push(new Timestamped(0, s.now()));91      d.dispose();92    });93    s.start();94    arrayEquals(list, [95      new Timestamped(0, time(1))96    ]);97  });98  test('advance to', function () {99    var s = new HistoricalScheduler();100    var list = [];101    s.scheduleAbsolute(null, time(0), function () { list.push(new Timestamped(0, s.now())); });102    s.scheduleAbsolute(null, time(1), function () { list.push(new Timestamped(1, s.now())); });103    s.scheduleAbsolute(null, time(2), function () { list.push(new Timestamped(2, s.now())); });104    s.scheduleAbsolute(null, time(10), function () { list.push(new Timestamped(10, s.now())); });105    s.scheduleAbsolute(null, time(11), function () { list.push(new Timestamped(11, s.now())); });106    s.advanceTo(time(8));107    equal(time(8), s.now());108    equal(time(8), s.clock);109    arrayEquals(list, [110      new Timestamped(0, time(0)),111      new Timestamped(1, time(1)),112      new Timestamped(2, time(2))113    ]);114    s.advanceTo(time(8));115    equal(time(8), s.now());116    equal(time(8), s.clock);117    arrayEquals(list, [118      new Timestamped(0, time(0)),119      new Timestamped(1, time(1)),120      new Timestamped(2, time(2))121    ]);122    s.scheduleAbsolute(null, time(7), function () { list.push(new Timestamped(7, s.now())); });123    s.scheduleAbsolute(null, time(8), function () { list.push(new Timestamped(8, s.now())); });124    equal(time(8), s.now());125    equal(time(8), s.clock);126    arrayEquals(list, [127      new Timestamped(0, time(0)),128      new Timestamped(1, time(1)),129      new Timestamped(2, time(2))130    ]);131    s.advanceTo(time(10));132    equal(time(10), s.now());133    equal(time(10), s.clock);134    arrayEquals(list, [135      new Timestamped(0, time(0)),136      new Timestamped(1, time(1)),137      new Timestamped(2, time(2)),138      new Timestamped(7, time(8)),139      new Timestamped(8, time(8)),140      new Timestamped(10, time(10))141    ]);142    s.advanceTo(time(100));143    equal(time(100), s.now());144    equal(time(100), s.clock);145    arrayEquals(list, [146      new Timestamped(0, time(0)),147      new Timestamped(1, time(1)),148      new Timestamped(2, time(2)),149      new Timestamped(7, time(8)),150      new Timestamped(8, time(8)),151      new Timestamped(10, time(10)),152      new Timestamped(11, time(11))153    ]);154  });155  test('advance by', function () {156    var s = new HistoricalScheduler();157    var list = [];158    s.scheduleAbsolute(null, time(0), function () { list.push(new Timestamped(0, s.now())); });159    s.scheduleAbsolute(null, time(1), function () { list.push(new Timestamped(1, s.now())); });160    s.scheduleAbsolute(null, time(2), function () { list.push(new Timestamped(2, s.now())); });161    s.scheduleAbsolute(null, time(10), function () { list.push(new Timestamped(10, s.now())); });162    s.scheduleAbsolute(null, time(11), function () { list.push(new Timestamped(11, s.now())); });163    s.advanceBy(time(8) - s.now());164    equal(time(8), s.now());165    equal(time(8), s.clock);166    arrayEquals(list, [167      new Timestamped(0, time(0)),168      new Timestamped(1, time(1)),169      new Timestamped(2, time(2))170    ]);171    s.scheduleAbsolute(null, time(7), function () { list.push(new Timestamped(7, s.now())); });172    s.scheduleAbsolute(null, time(8), function () { list.push(new Timestamped(8, s.now())); });173    equal(time(8), s.now());174    equal(time(8), s.clock);175    arrayEquals(list, [176      new Timestamped(0, time(0)),177      new Timestamped(1, time(1)),178      new Timestamped(2, time(2))179    ]);180    s.advanceBy(0);181    equal(time(8), s.now());182    equal(time(8), s.clock);183    arrayEquals(list, [184      new Timestamped(0, time(0)),185      new Timestamped(1, time(1)),186      new Timestamped(2, time(2))187    ]);188    s.advanceBy(fromDays(2));189    equal(time(10), s.now());190    equal(time(10), s.clock);191    arrayEquals(list, [192      new Timestamped(0, time(0)),193      new Timestamped(1, time(1)),194      new Timestamped(2, time(2)),195      new Timestamped(7, time(8)),196      new Timestamped(8, time(8)),197      new Timestamped(10, time(10))198    ]);199    s.advanceBy(fromDays(90));200    equal(time(100), s.now());201    equal(time(100), s.clock);202    arrayEquals(list, [203      new Timestamped(0, time(0)),204      new Timestamped(1, time(1)),205      new Timestamped(2, time(2)),206      new Timestamped(7, time(8)),207      new Timestamped(8, time(8)),208      new Timestamped(10, time(10)),209      new Timestamped(11, time(11))210    ]);211  });212  test('is enabled', function () {213    var s = new HistoricalScheduler();214    equal(false, s.isEnabled);215    s.schedule(s, function (s) {216      equal(true, s.isEnabled);217      s.stop();218      equal(false, s.isEnabled);219    });220    equal(false, s.isEnabled);221    s.start();222    equal(false, s.isEnabled);223  });224  test('Sleep 1', function () {225    var now = new Date(1983, 2, 11, 12, 0, 0).getTime();226    var s = new HistoricalScheduler(now);227    s.sleep(fromDays(1));228    equal(now + fromDays(1), s.clock);229  });230  test('sleep 2', function () {231    var s = new HistoricalScheduler();232    var n = 0;233    s.scheduleRecursiveFuture(null, new Date(s.now() + 6000), function (_, rec) {234      s.sleep(3 * 6000);235      n++;236      rec(null, new Date(s.now() + 6000));237    });238    s.advanceTo(s.now() + (5 * 6000));239    equal(2, n);240  });241  function reverseComparer (x, y) {242    return y - x;243  }244  test('with comparer', function () {245    var now = new Date();246    var s = new HistoricalScheduler(now, reverseComparer);247    var res = [];248    s.scheduleAbsolute(null, now - 1000, function () { res.push(1); });249    s.scheduleAbsolute(null, now - 2000, function () { res.push(2); });250    s.start();251    arrayEquals(res, [1,2]);252  });...arrayEquals.test.js
Source:arrayEquals.test.js  
...5  const arrThree = [1, { three: 2 }]6  const arrFour = [1, { three: 2 }, true, [1, 2, 3]]7  const arrFive = [1, { three: 2 }]8  it('should return false if the arrays are different', () => {9    expect(arrayEquals(arrOne, arrTwo)).toEqual(false)10    expect(arrayEquals(arrOne, arrThree)).toEqual(false)11    expect(arrayEquals(arrOne, arrFour)).toEqual(false)12    expect(arrayEquals(arrOne, true)).toEqual(false)13  })14  it('should return true if the arrays are equals', () => {15    expect(arrayEquals(arrOne, arrOne)).toEqual(true)16    expect(arrayEquals(arrThree, arrFive)).toEqual(true)17  })18  it('should throw an error if the first parameter is not an array', () => {19    expect(() => arrayEquals({}, arrOne)).toThrowError(TypeError)20  })21  it('should return false if the second parameter is not an array', () => {22    expect(arrayEquals(arrOne, {})).toEqual(false)23  })...Using AI Code Generation
1assert(arrayEquals([1, 2, 3], [1, 2, 3]));2assert(arrayEquals([1, 2, 3], [1, 2, 3]));3assert(arrayEquals([1, 2, 3], [1, 2, 3]));4assert(arrayEquals([1, 2, 3], [1, 2, 3]));5assert(arrayEquals([1, 2, 3], [1, 2, 3]));6assert(arrayEquals([1, 2, 3], [1, 2, 3]));7assert(arrayEquals([1, 2, 3], [1, 2, 3]));8assert(arrayEquals([1, 2, 3], [1, 2, 3]));9assert(arrayEquals([1, 2, 3], [1, 2, 3]));10assert(arrayEquals([1, 2, 3], [1, 2, 3]));11assert(arrayEquals([1, 2, 3], [1, 2, 3]));12assert(arrayEquals([1, 2, 3], [1, 2, 3]));13assert(arrayEquals([1, 2, 3], [1, 2, 3]));14assert(arrayEquals([Using AI Code Generation
1assert(arrayEquals([1, 2, 3], [1, 2, 3]), "Arrays are equal");2assert(arrayEquals([1, 2, 3], [1, 2, 4]), "Arrays are not equal");3assert(arrayEquals([1, 2, 3], [1, 2, 3]), "Arrays are equal");4assert(arrayEquals([1, 2, 3], [1, 2, 4]), "Arrays are not equal");5assert(arrayEquals([1, 2, 3], [1, 2, 3]), "Arrays are equal");6assert(arrayEquals([1, 2, 3], [1, 2, 4]), "Arrays are not equal");7assert(arrayEquals([1, 2, 3], [1, 2, 3]), "Arrays are equal");8assert(arrayEquals([1, 2, 3], [1, 2, 4]), "Arrays are not equal");9assert(arrayEquals([1, 2, 3], [1, 2, 3]), "Arrays are equal");10assert(arrayEquals([1, 2, 3], [1, 2, 4]), "Arrays are not equal");11assert(arrayEquals([1, 2, 3], [1, 2, 3]), "Arrays are equal");12assert(arrayEquals([1, 2, 3], [1, 2, 4]), "Arrays are not equal");13assert(arrayEquals([1, 2, 3], [1, 2, 3]), "Arrays are equal");14assert(arrayEquals([1, 2, 3], [1, 2, 4]), "Arrays are not equal");15assert(arrayEquals([1, 2Using AI Code Generation
1var assert = require('assert');2var sinon = require('sinon');3var arrayEquals = sinon.assert.arrayEquals;4var array1 = [1,2,3];5var array2 = [1,2,3];6var array3 = [1,2,3];7var array4 = [3,2,1];Using AI Code Generation
1var sinon = require('sinon');2var assert = sinon.assert;3var arrayEquals = assert.arrayEquals;4var array = [1, 2, 3];5var array2 = [1, 2, 3];6arrayEquals(array, array2);7arrayEquals(array, [1, 2, 3]);8arrayEquals(array, [1, 2, 3, 4]);9arrayEquals(array, [1, 2, 4]);10arrayEquals(array, [1, 2, 3, 4], 'array is equal to [1, 2, 3, 4]');11var sinon = require('sinon');12var assert = sinon.assert;13var array = [1, 2, 3];14var array2 = [1, 2, 3];15var array3 = [1, 2, 3];16var array4 = [1, 2, 3];17var array5 = [1, 2, 3];18assert.arrayEquals(array, array2);19assert.arrayEquals(array, [1, 2, 3]);20assert.arrayEquals(array, [1, 2, 3, 4]);21assert.arrayEquals(array, [1, 2, 4]);22assert.arrayEquals(array, [1, 2, 3, 4], 'array is equal to [1, 2, 3, 4]');23var sinon = require('sinon');24var assert = sinon.assert;25var array = [1, 2, 3];26var array2 = [1, 2, 3];27var array3 = [1, 2, 3];28var array4 = [1, 2, 3];29var array5 = [1, 2, 3];30assert.arrayEquals(array, array2);31assert.arrayEquals(array, [1, 2, 3]);32assert.arrayEquals(array, [1, 2, 3, 4]);33assert.arrayEquals(array, [1, 2, 4]);34assert.arrayEquals(array, [1, 2, 3, 4], 'array is equal to [1, 2, 3, 4]');Using AI Code Generation
1var sinon = require('sinon');2var assert = sinon.assert;3var arrayEquals = sinon.match.arrayEquals;4var chai = require('chai');5var assert = chai.assert;6var arrayEquals = chai.match.arrayEquals;7var expect = require('expect');8var arrayEquals = expect.arrayEquals;9var should = require('should');10var arrayEquals = should.arrayEquals;11var nodeunit = require('nodeunit');12var arrayEquals = nodeunit.assert.arrayEquals;13var jasmine = require('jasmine');14var arrayEquals = jasmine.arrayEquals;15var mocha = require('mocha');16var arrayEquals = mocha.assert.arrayEquals;17var vows = require('vows');18var arrayEquals = vows.assert.arrayEquals;19var qunit = require('qunit');20var arrayEquals = qunit.assert.arrayEquals;21var tap = require('node-tap');22var arrayEquals = tap.assert.arrayEquals;23var nodeunit = require('nodeunit');24var arrayEquals = nodeunit.assert.arrayEquals;25var should = require('should');26var arrayEquals = should.arrayEquals;27var expect = require('expect');28var arrayEquals = expect.arrayEquals;29var chai = require('chai');30var assert = chai.assert;31var arrayEquals = chai.match.arrayEquals;32var sinon = require('sinon');33var assert = sinon.assert;34var arrayEquals = sinon.match.arrayEquals;35var nodeunit = require('nodeunit');36var arrayEquals = nodeunit.assert.arrayEquals;37var should = require('should');38var arrayEquals = should.arrayEquals;39var expect = require('expect');Using AI Code Generation
1var arrayEquals = require('sinon-chai').arrayEquals;2chai.use(arrayEquals);3var sinon = require('sinon-chai');4chai.use(sinon);5var sinon = require('sinon-chai');6chai.use(sinon);7var sinon = require('sinon-chai');8chai.use(sinon);9var sinon = require('sinon-chai');10chai.use(sinon);11var sinon = require('sinon-chai');12chai.use(sinon);13var sinon = require('sinon-chai');14chai.use(sinon);15var sinon = require('sinon-chai');16chai.use(sinon);17var sinon = require('sinon-chai');18chai.use(sinon);19var sinon = require('sinon-chai');20chai.use(sinon);21var sinon = require('sinon-chai');22chai.use(sinon);23var sinon = require('sinon-chai');24chai.use(sinon);25var sinon = require('sinon-chai');26chai.use(sinon);27var sinon = require('sinon-chai');28chai.use(sinon);29var sinon = require('sinon-chai');30chai.use(sinon);31var sinon = require('sinon-chai');32chai.use(sinon);33var sinon = require('sinon-chai');34chai.use(sinon);35var sinon = require('sinon-chai');36chai.use(sinon);37var sinon = require('sinon-chai');38chai.use(sinon);39var sinon = require('sinon-chai');40chai.use(sinon);41var sinon = require('sinon-chai');42chai.use(sinon);43var sinon = require('sinon-chai');Using AI Code Generation
1var arrayEquals = sinon.match.array.equals;2var deepEquals = sinon.match.deepEquals;3var functionEquals = sinon.match.func.equals;4var objectEquals = sinon.match.object.equals;5var stringEquals = sinon.match.string.equals;6var typeOf = sinon.match.typeOf;7var instanceOf = sinon.match.instanceOf;8var has = sinon.match.has;9var hasOwn = sinon.match.hasOwn;10var hasNested = sinon.match.hasNested;11var isNull = sinon.match.isNull;12var isUndefined = sinon.match.isUndefined;13var isTrue = sinon.match.isTrue;14var isFalse = sinon.match.isFalse;15var isBoolean = sinon.match.isBoolean;16var isNumber = sinon.match.isNumber;17var isString = sinon.match.isString;18var isObject = sinon.match.isObject;19var isFunction = sinon.match.isFunction;20var isDate = sinon.match.isDate;21var isArray = sinon.match.isArray;22var isRegExp = sinon.match.isRegExp;23var isNaN = sinon.match.isNaN;24var isFinite = sinon.match.isFinite;25var isSymbol = sinon.match.isSymbol;Using AI Code Generation
1var sinon = require('sinon');2var assert = sinon.assert;3var arrayEquals = sinon.match.arrayEquals;4var testArray = [1,2,3,4,5];5var testArray2 = [1,2,3,4,5];6var testArray3 = [1,2,3,4,6];7assert(arrayEquals(testArray, testArray2));8assert(!arrayEquals(testArray, testArray3));Using AI Code Generation
1var sinon = require('sinon');2var assert = sinon.assert;3var test = require('./test.js');4var testArray = [1,2,3];5var testArray2 = [1,2,3];6assert(arrayEquals(testArray,testArray2));7assert(arrayEquals(testArray,[1,2,3,4]));8assert(sinon.match.same(testArray,testArray2));9assert(sinon.match.same(testArray,[1,2,3,4]));10var test = require('./test.js');11var sinon = require('sinon');12var assert = sinon.assert;13var callback = sinon.spy();14test(callback);15assert(callback.calledOnce);16var test = require('./test.js');17var sinon = require('sinon');18var assert = sinon.assert;19var callback = sinon.spy();20test(callback);21assert(callback.calledOnce);22var test = require('./test.js');23var sinon = require('sinon');24var assert = sinon.assert;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!!
