Best JavaScript code snippet using chai
tree-sortable-debug.js
Source:tree-sortable-debug.js
...213 if (comparator._unboundComparator === Sortable.prototype.sortComparator) {214 return reverse ? 0 : max;215 }216 var compare = reverse ? this._compareReverse : this._compare,217 needle = comparator(node);218 // Perform an iterative binary search to determine the correct position219 // for the node based on the return value of the comparator function.220 var middle;221 while (min < max) {222 middle = (min + max) >> 1; // Divide by two and discard remainder.223 if (compare(comparator(children[middle]), needle) < 0) {224 min = middle + 1;225 } else {226 max = middle;227 }228 }229 return min;230 },231 /**232 Returns a sort comparator function derived from the given _node_ and233 _options_, and bound to the correct `thisObj` based on where it was found.234 @method _getSortComparator235 @param {Tree.Node} node Node on which to look for a `sortComparator`236 function.237 @param {Object} [options] Options object on which to look for a238 `sortComparator` function.239 @return {Function} Properly bound sort comparator function.240 @protected241 **/242 _getSortComparator: function (node, options) {243 var boundComparator,244 comparator,245 thisObj;246 if (options && options.sortComparator) {247 comparator = node.sortComparator = options.sortComparator;248 } else if (node.sortComparator) {249 comparator = node.sortComparator;250 thisObj = node;251 } else {252 comparator = this.sortComparator;253 thisObj = this;254 }255 boundComparator = function () {256 return comparator.apply(thisObj, arguments);257 };258 boundComparator._unboundComparator = comparator;259 return boundComparator;260 },261 /**262 Array sort function used by `sortNode()` to re-sort a node's children.263 @method _sort264 @param {Tree.Node} a First node to compare.265 @param {Tree.Node} b Second node to compare.266 @param {Function} comparator Comparator function.267 @param {Boolean} [reverse=false] If `true`, this will be a reverse268 (descending) comparison.269 @return {Number} `-1` if _a_ is less than _b_, `0` if equal, `1` if greater.270 @protected271 **/272 _sort: function (a, b, comparator, reverse) {273 return this[reverse ? '_compareReverse' : '_compare'](274 comparator(a), comparator(b));275 }276};277Y.Tree.Sortable = Sortable;278/**279@module tree280@submodule tree-sortable281**/282/**283`Tree.Node` extension that adds methods useful for nodes in trees that use the284`Tree.Sortable` extension.285@class Tree.Node.Sortable286@constructor287@extensionfor Tree.Node288**/...
Comparator.test.js
Source:Comparator.test.js
1import Comparator from '../Comparator';2describe('Comparator', () => {3 it('should compare with default comparator function', () => {4 const comparator = new Comparator();5 expect(comparator.equal(0, 0)).toBe(true);6 expect(comparator.equal(0, 1)).toBe(false);7 expect(comparator.equal('a', 'a')).toBe(true);8 expect(comparator.lessThan(1, 2)).toBe(true);9 expect(comparator.lessThan(-1, 2)).toBe(true);10 expect(comparator.lessThan('a', 'b')).toBe(true);11 expect(comparator.lessThan('a', 'ab')).toBe(true);12 expect(comparator.lessThan(10, 2)).toBe(false);13 expect(comparator.lessThanOrEqual(10, 2)).toBe(false);14 expect(comparator.lessThanOrEqual(1, 1)).toBe(true);15 expect(comparator.lessThanOrEqual(0, 0)).toBe(true);16 expect(comparator.greaterThan(0, 0)).toBe(false);17 expect(comparator.greaterThan(10, 0)).toBe(true);18 expect(comparator.greaterThanOrEqual(10, 0)).toBe(true);19 expect(comparator.greaterThanOrEqual(10, 10)).toBe(true);20 expect(comparator.greaterThanOrEqual(0, 10)).toBe(false);21 });22 it('should compare with custom comparator function', () => {23 const comparator = new Comparator((a, b) => {24 if (a.length === b.length) {25 return 0;26 }27 return a.length < b.length ? -1 : 1;28 });29 expect(comparator.equal('a', 'b')).toBe(true);30 expect(comparator.equal('a', '')).toBe(false);31 expect(comparator.lessThan('b', 'aa')).toBe(true);32 expect(comparator.greaterThanOrEqual('a', 'aa')).toBe(false);33 expect(comparator.greaterThanOrEqual('aa', 'a')).toBe(true);34 expect(comparator.greaterThanOrEqual('a', 'a')).toBe(true);35 comparator.reverse();36 expect(comparator.equal('a', 'b')).toBe(true);37 expect(comparator.equal('a', '')).toBe(false);38 expect(comparator.lessThan('b', 'aa')).toBe(false);39 expect(comparator.greaterThanOrEqual('a', 'aa')).toBe(true);40 expect(comparator.greaterThanOrEqual('aa', 'a')).toBe(false);41 expect(comparator.greaterThanOrEqual('a', 'a')).toBe(true);42 });...
Using AI Code Generation
1const _ = {};2_.each = function(list, callback) {3 if (Array.isArray(list)) {4 for (let i = 0; i < list.length; i++) {5 callback(list[i], i, list);6 }7 } else {8 for (let key in list) {9 callback(list[key], key, list);10 }11 }12};13_.filter = function(arr, callback) {14 const storage = [];15 _.each(arr, function(item, i, list) {16 if (callback(item, i, list)) {17 storage.push(item);18 }19 });20 return storage;21};22_.map = function(arr, callback) {23 const storage = [];24 _.each(arr, function(item, i, list) {25 storage.push(callback(item, i, list));26 });27 return storage;28};29_.reduce = function(arr, callback, memo) {30 if (memo === undefined) {31 memo = arr[0];32 for (let i = 1; i < arr.length; i++) {33 memo = callback(memo, arr[i], i, arr);34 }35 } else {36 _.each(arr, function(item, i, list) {37 memo = callback(memo, item, i, list);38 });39 }40 return memo;41};42_.find = function(arr, callback) {43 for (let i = 0; i < arr.length; i++) {44 if (callback(arr[i], i, arr)) {45 return arr[i];46 }47 }48};
Using AI Code Generation
1var http = require('http');2var fs = require('fs');3http.createServer(function (req, res) {4 fs.readFile('demo.html', function(err, data) {5 res.writeHead(200, {'Content-Type': 'text/html'});6 res.write(data);7 res.end();8 });9}).listen(8080);
Using AI Code Generation
1const {Builder, By, Key, until} = require('selenium-webdriver');2const assert = require('assert');3const driver = new Builder().forBrowser('firefox').build();4driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);5driver.wait(until.titleIs('webdriver - Google Search'), 1000);6driver.wait(until.titleIs('webdriver - Google Search'), 1000);7driver.wait(until.titleIs('webdriver - Google Search'), 1000);8driver.wait(until.titleIs('webdriver - Google Search'), 1000);9driver.wait(until.titleIs('webdriver - Google Search'), 1000);10driver.wait(until.titleIs('webdriver - Google Search'), 1000);11driver.wait(until.titleIs('webdriver - Google Search'), 1000);12driver.wait(until.titleIs('webdriver - Google Search'), 1000);13driver.wait(until.titleIs('webdriver - Google Search'), 1000);14driver.wait(until.titleIs('webdriver - Google Search'), 1000);15driver.wait(until.titleIs('webdriver - Google Search'), 1000);16driver.wait(until.titleIs('webdriver - Google Search'), 1000);17driver.wait(until.titleIs('webdriver - Google Search'), 1000);18driver.wait(until.titleIs('webdriver - Google Search'), 1000);19driver.wait(until.titleIs('webdriver - Google
Using AI Code Generation
1var expect = require('chai').expect;2var assert = require('chai').assert;3var should = require('chai').should();4var app = require('../app');5var supertest = require('supertest');6var request = supertest(app);7var chai = require('chai');8var chaiHttp = require('chai-http');9chai.use(chaiHttp);10describe('GET /', function() {11 it('should return 200 OK', function(done) {12 request.get('/')13 .expect(200, done);14 });15});16describe('GET /', function() {17 it('should return 200 OK', function(done) {18 request.get('/')19 .expect(200, done);20 });21});22describe('GET /', function() {23 it('should return 200 OK', function(done) {24 request.get('/')25 .expect(200, done);26 });27});28describe('GET /', function() {29 it('should return 200 OK', function(done) {30 request.get('/')31 .expect(200, done);32 });33});34describe('GET /', function() {35 it('should return 200 OK', function(done) {36 request.get('/')37 .expect(200, done);38 });39});40describe('GET /', function() {41 it('should return 200 OK', function(done) {42 request.get('/')43 .expect(200, done);44 });45});46describe('GET /', function() {47 it('should return 200 OK', function(done) {48 request.get('/')49 .expect(200, done);50 });51});52describe('GET /', function() {53 it('should return 200 OK', function(done) {54 request.get('/')55 .expect(200, done);56 });57});58describe('GET /', function() {59 it('should return 200 OK', function(done) {60 request.get('/')61 .expect(200, done);62 });63});64describe('
Using AI Code Generation
1var myArray = [1, 2, 3, 4, 5, 6];2myArray = myArray.filter(function (num) {3 return num % 2 === 0;4}).map(function (num) {5 return num * 2;6});
Using AI Code Generation
1let arr = [1, 2, 3, 4, 5, 6];2let result = arr.filter((ele) => {3 return ele > 3;4});5console.log(result);6let arr = [1, 2, 3, 4, 5, 6];7let result = arr.filter((ele) => {8 return ele > 3;9});10console.log(result);11let arr = [1, 2, 3, 4, 5, 6];12let result = arr.filter((ele) => {13 return ele > 3;14});15console.log(result);16let arr = [1, 2, 3, 4, 5, 6];17let result = arr.filter((ele) => {18 return ele > 3;19});20console.log(result);21let arr = [1, 2, 3, 4, 5, 6];22let result = arr.filter((ele) => {23 return ele > 3;24});25console.log(result);26let arr = [1, 2, 3, 4, 5, 6];27let result = arr.filter((ele) => {28 return ele > 3;29});30console.log(result);31let arr = [1, 2, 3, 4, 5, 6];32let result = arr.filter((ele) => {33 return ele > 3;34});35console.log(result);36let arr = [1, 2, 3, 4, 5, 6];37let result = arr.filter((ele) => {38 return ele > 3;39});40console.log(result);41let arr = [1, 2, 3, 4, 5, 6];42let result = arr.filter((ele) => {43 return ele > 3;44});45console.log(result);
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!!