Best JavaScript code snippet using mocha
cleaner.js
Source:cleaner.js  
1'use strict';2const expect = require('chai').expect;3const cleaner = require(__dirname + '/../src/cleaner');4module.exports = function() {5    suite('cleaner', function() {6        test('clean cli html code', function(done) {7            const cli = cleaner.cleanCli('<code>--test-argument</code>');8            expect(cli).to.equal('--test-argument');9            done();10        });11        test('clean cli html code not closed', function(done) {12            const cli = cleaner.cleanCli('<code>--test-argument');13            expect(cli).to.equal('--test-argument');14            done();15        });16        test('clean cli nothing to clean', function(done) {17            const cli = cleaner.cleanCli('--test-argument');18            expect(cli).to.equal('--test-argument');19            done();20        });21        test('clean cli undefined', function(done) {22            const cli = cleaner.cleanCli(undefined);23            expect(cli).to.equal(undefined);24            done();25        });26        test('clean range undefined', function(done) {27            const range = cleaner.cleanRange(undefined);28            expect(range).to.deep.equal(undefined);29            done();30        });31        test('clean range.from typeof object (dataset-1)', function(done) {32            const range = cleaner.cleanRange({33                from: null,34                to: null,35            });36            expect(range).to.deep.equal({});37            done();38        });39        test('clean range.from typeof object (dataset-2)', function(done) {40            const range = cleaner.cleanRange({41                to: null,42            });43            expect(range).to.deep.equal({});44            done();45        });46        test('clean range.from typeof object (dataset-3)', function(done) {47            const range = cleaner.cleanRange({48                from: null,49            });50            expect(range).to.deep.equal({});51            done();52        });53        test('clean range.from typeof object (dataset-4)', function(done) {54            const range = cleaner.cleanRange({55                from: undefined,56                to: undefined,57            });58            expect(range).to.deep.equal({});59            done();60        });61        test('clean range.from typeof object (dataset-5)', function(done) {62            const range = cleaner.cleanRange({63                to: undefined,64            });65            expect(range).to.deep.equal({});66            done();67        });68        test('clean range.from typeof object (dataset-6)', function(done) {69            const range = cleaner.cleanRange({70                from: undefined,71            });72            expect(range).to.deep.equal({});73            done();74        });75        test('clean range.from typeof object (dataset-7)', function(done) {76            const range = cleaner.cleanRange({77                from: NaN,78                to: NaN,79            });80            expect(range).to.deep.equal({});81            done();82        });83        test('clean range.from typeof int', function(done) {84            const range = cleaner.cleanRange({85                from: 1024,86            });87            expect(range).to.deep.equal({88                from: 1024,89            });90            done();91        });92        test('clean range.from typeof string', function(done) {93            const range = cleaner.cleanRange({94                from: '1024',95            });96            expect(range).to.deep.equal({});97            done();98        });99        test('clean range.to typeof int', function(done) {100            const range = cleaner.cleanRange({101                to: 1024,102            });103            expect(range).to.deep.equal({104                to: 1024,105            });106            done();107        });108        test('clean range.to typeof string', function(done) {109            const range = cleaner.cleanRange({110                to: '1024',111            });112            expect(range).to.deep.equal({});113            done();114        });115        test('clean range.to typeof object', function(done) {116            const range = cleaner.cleanRange({117                to: {},118            });119            expect(range).to.deep.equal({});120            done();121        });122        test('clean range to upwards', function(done) {123            const range = cleaner.cleanRange({124                to: 'upwards',125            });126            expect(range).to.deep.equal({127                to: 'upwards',128            });129            done();130        });131        test('clean range to upwards match', function(done) {132            const range = cleaner.cleanRange({133                to: '(128KB) upwards',134            });135            expect(range).to.deep.equal({136                to: 'upwards',137            });138            done();139        });140        test('clean binary types in bytes', function(done) {141            const type = cleaner.cleanType('in bytes');142            expect(type).to.deep.equal('byte');143            done();144        });145        test('clean binary types size in mb', function(done) {146            const type = cleaner.cleanType('size in mb');147            expect(type).to.deep.equal('byte');148            done();149        });150        test('clean binary types number of bytes', function(done) {151            const type = cleaner.cleanType('number of bytes');152            expect(type).to.deep.equal('byte');153            done();154        });155        test('clean binary types number of', function(done) {156            const type = cleaner.cleanType('number of');157            expect(type).to.deep.equal('integer');158            done();159        });160        test('clean binary types size of', function(done) {161            const type = cleaner.cleanType('size of');162            expect(type).to.deep.equal('integer');163            done();164        });165        test('clean binary types in microseconds', function(done) {166            const type = cleaner.cleanType('in microseconds');167            expect(type).to.deep.equal('integer');168            done();169        });170        test('clean binary types in seconds', function(done) {171            const type = cleaner.cleanType('in seconds');172            expect(type).to.deep.equal('integer');173            done();174        });175        test('clean wtf type', function(done) {176            const type = cleaner.cleanType('wtf');177            expect(type).to.deep.equal(undefined);178            done();179        });180        test('clean enumeration type', function(done) {181            const type = cleaner.cleanType('enumeration');182            expect(type).to.deep.equal('enumeration');183            done();184        });185        test('clean undefined type', function(done) {186            const type = cleaner.cleanType(undefined);187            expect(type).to.deep.equal(undefined);188            done();189        });190    });...laundry.js
Source:laundry.js  
1const getMaxPair = require('../src/laundry');2describe("Anna's Laundry assumptions", () => {3  test('1. Example data', () => {4    const numberMachineCanWash = 0;5    const cleanPile = [1, 2, 1, 1];6    const dirtyPile = [1, 4, 3, 2, 4];7    expect(getMaxPair(numberMachineCanWash, cleanPile, dirtyPile)).toBe(1);8  });9  test('2. Example data', () => {10    const numberMachineCanWash = 2;11    const cleanPile = [1, 2, 1, 1];12    const dirtyPile = [1, 4, 3, 2, 4];13    expect(getMaxPair(numberMachineCanWash, cleanPile, dirtyPile)).toBe(3);14  });15  test('3. Example data', () => {16    const numberMachineCanWash = 4;17    const cleanPile = [1, 2, 1, 1];18    const dirtyPile = [1, 4, 3, 2, 4];19    expect(getMaxPair(numberMachineCanWash, cleanPile, dirtyPile)).toBe(4);20  });21});22describe("Anna's Laundry Spec", () => {23  test('for a simple case', () => {24    const numberMachineCanWash = 2;25    const cleanPile = [1, 2, 3, 1, 2, 3];26    const dirtyPile = [3, 3, 4, 1, 2, 7, 9];27    expect(getMaxPair(numberMachineCanWash, cleanPile, dirtyPile)).toBe(4);28  });29  test('For another simple case where the maximum number is five', () => {30    const numberMachineCanWash = 4;31    const cleanPile = [1, 1, 1, 1, 1, 1];32    const dirtyPile = [1, 2, 2, 1, 3, 4, 5, 2];33    expect(getMaxPair(numberMachineCanWash, cleanPile, dirtyPile)).toBe(5);34  });35  test('For a case where the machine cannot wash anything and there are no pairs', () => {36    const numberMachineCanWash = 0;37    const cleanPile = [1];38    const dirtyPile = [1, 2, 3, 4, 5, 5];39    expect(getMaxPair(numberMachineCanWash, cleanPile, dirtyPile)).toBe(0);40  });41  test('For a case where the clean socks are large numbers', () => {42    const numberMachineCanWash = 20;43    const cleanPile = [50, 50, 50, 37, 38, 37, 49, 39, 38, 45, 43];44    const dirtyPile = [50];45    expect(getMaxPair(numberMachineCanWash, cleanPile, dirtyPile)).toBe(4);46  });47  test('For a case where the dirty socks are large numbers', () => {48    const numberMachineCanWash = 20;49    const cleanPile = [1];50    const dirtyPile = [50, 50, 50, 37, 38, 37, 49, 39, 38, 45, 43];51    expect(getMaxPair(numberMachineCanWash, cleanPile, dirtyPile)).toBe(3);52  });53  test('For a case where the numbers are large', () => {54    const numberMachineCanWash = 50;55    const cleanPile = [40, 40, 40, 40, 40, 40, 40, 50, 50, 50, 50, 50];56    const dirtyPile = [40, 40, 45, 45, 30, 35, 50, 50, 25, 25, 20, 20];57    expect(getMaxPair(numberMachineCanWash, cleanPile, dirtyPile)).toBe(10);58  });59  test('For a case where the clean and dirty array have on element each', () => {60    const numberMachineCanWash = 1;61    const cleanPile = [8];62    const dirtyPile = [8];63    expect(getMaxPair(numberMachineCanWash, cleanPile, dirtyPile)).toBe(1);64  });65  test('For a case where the clean and dirty array have no colour of socks in common', () => {66    const numberMachineCanWash = 20;67    const cleanPile = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];68    const dirtyPile = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20];69    expect(getMaxPair(numberMachineCanWash, cleanPile, dirtyPile)).toBe(0);70  });71  test('For a case where the clean and dirty array have all colors in common and are of equal length', () => {72    const numberMachineCanWash = 20;73    const cleanPile = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5];74    const dirtyPile = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5];75    expect(getMaxPair(numberMachineCanWash, cleanPile, dirtyPile)).toBe(10);76  });77  test('For a case where the clean and dirty array have all colors in common and are not of equal length', () => {78    const numberMachineCanWash = 20;79    const cleanPile = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5];80    const dirtyPile = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5];81    expect(getMaxPair(numberMachineCanWash, cleanPile, dirtyPile)).toBe(10);82  });83  test('For a case where the machine cannot wash any socks', () => {84    const numberMachineCanWash = 0;85    const cleanPile = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5];86    const dirtyPile = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5];87    expect(getMaxPair(numberMachineCanWash, cleanPile, dirtyPile)).toBe(5);88  });89  test('For a case where all the socks he can take are initially dirty and the machine can wash all of them', () => {90    const numberMachineCanWash = 30;91    const cleanPile = [1, 2, 3, 4, 6, 7, 8, 9, 10, 11];92    const dirtyPile = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5];93    expect(getMaxPair(numberMachineCanWash, cleanPile, dirtyPile)).toBe(6);94  });95  test('For a case where all the socks he can take are initially dirty and the machine only 4', () => {96    const numberMachineCanWash = 4;97    const cleanPile = [1, 2, 3, 4, 6, 7, 8, 9, 10, 11];98    const dirtyPile = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5];99    expect(getMaxPair(numberMachineCanWash, cleanPile, dirtyPile)).toBe(2);100  });101  test('For a case of re-occurring elements', () => {102    const numberMachineCanWash = 5;103    const cleanPile = [1, 2, 3, 2, 3, 4, 5];104    const dirtyPile = [2, 1, 1, 1, 3, 3, 3, 4, 4, 4, 5, 5, 6, 5, 7, 5, 6];105    expect(getMaxPair(numberMachineCanWash, cleanPile, dirtyPile)).toBe(6);106  });107  test('For another case of re-occurring elements where k = 10', () => {108    const numberMachineCanWash = 10;109    const cleanPile = [110      10,111      11,112      12,113      11,114      10,115      10,116      13,117      11,118      12,119      10,120      13,121      14,122      11,123      10,124      12,125    ];126    const dirtyPile = [127      10,128      10,129      11,130      12,131      13,132      10,133      14,134      14,135      14,136      12,137      12,138      10,139      10,140      11,141      11,142    ];143    expect(getMaxPair(numberMachineCanWash, cleanPile, dirtyPile)).toBe(12);144  });145  test('For another case of re-occurring elements where k = 0', () => {146    const numberMachineCanWash = 0;147    const cleanPile = [148      10,149      11,150      12,151      11,152      10,153      10,154      13,155      11,156      12,157      10,158      13,159      14,160      11,161      10,162      12,163    ];164    const dirtyPile = [165      10,166      10,167      11,168      12,169      13,170      10,171      14,172      14,173      14,174      12,175      12,176      10,177      10,178      11,179      11,180    ];181    expect(getMaxPair(numberMachineCanWash, cleanPile, dirtyPile)).toBe(6);182  });...system.js
Source:system.js  
1/**2 * Internal function to check using Ajax if clean URLs can be enabled on the3 * settings page.4 *5 * This function is not used to verify whether or not clean URLs6 * are currently enabled.7 */8Drupal.behaviors.cleanURLsSettingsCheck = function(context) {9  // This behavior attaches by ID, so is only valid once on a page.10  // Also skip if we are on an install page, as Drupal.cleanURLsInstallCheck will handle11  // the processing.12  if ($("#clean-url.clean-url-processed, #clean-url.install").size()) {13    return;14  }15  var url = Drupal.settings.basePath +"admin/settings/clean-urls/check";16  $("#clean-url .description span").html('<div id="testing">'+ Drupal.t('Testing clean URLs...') +"</div>");17  $("#clean-url p").hide();18  $.ajax({19    url: location.protocol +"//"+ location.host + url,20    dataType: 'json',21    success: function () {22      // Check was successful.23      $("#clean-url input.form-radio").attr("disabled", false);24      $("#clean-url .description span").append('<div class="ok">'+ Drupal.t('Your server has been successfully tested to support this feature.') +"</div>");25      $("#testing").hide();26    },27    error: function() {28      // Check failed.29      $("#clean-url .description span").append('<div class="warning">'+ Drupal.t('Your system configuration does not currently support this feature. The <a href="http://drupal.org/node/15365">handbook page on Clean URLs</a> has additional troubleshooting information.') +"</div>");30      $("#testing").hide();31    }32  });33  $("#clean-url").addClass('clean-url-processed');34};35/**36 * Internal function to check using Ajax if clean URLs can be enabled on the37 * install page.38 *39 * This function is not used to verify whether or not clean URLs40 * are currently enabled.41 */42Drupal.cleanURLsInstallCheck = function() {43  var url = location.protocol +"//"+ location.host + Drupal.settings.basePath +"admin/settings/clean-urls/check";44  $("#clean-url .description").append('<span><div id="testing">'+ Drupal.settings.cleanURL.testing +"</div></span>");45  $("#clean-url.install").css("display", "block");46  $.ajax({47    url: url,48    dataType: 'json',49    success: function () {50      // Check was successful.51      $("#clean-url input.form-radio").attr("disabled", false);52      $("#clean-url input.form-radio").attr("checked", 1);53      $("#clean-url .description span").append('<div class="ok">'+ Drupal.settings.cleanURL.success +"</div>");54      $("#testing").hide();55    },56    error: function() {57      // Check failed.58      $("#clean-url .description span").append('<div class="warning">'+ Drupal.settings.cleanURL.failure +"</div>");59      $("#testing").hide();60    }61  });62  $("#clean-url").addClass('clean-url-processed');63};64/**65 * When a field is filled out, apply its value to other fields that will likely66 * use the same value. In the installer this is used to populate the67 * administrator e-mail address with the same value as the site e-mail address.68 */69Drupal.behaviors.copyFieldValue = function (context) {70  for (var sourceId in Drupal.settings.copyFieldValue) {71    // Get the list of target fields.72    targetIds = Drupal.settings.copyFieldValue[sourceId];73    if (!$('#'+ sourceId + '.copy-field-values-processed').size(), context) {74      // Add the behavior to update target fields on blur of the primary field.75      sourceField = $('#' + sourceId);76      sourceField.bind('blur', function() {77        for (var delta in targetIds) {78          var targetField = $('#'+ targetIds[delta]);79          if (targetField.val() == '') {80            targetField.val(this.value);81          }82        }83      });84      sourceField.addClass('copy-field-values-processed');85    }86  }87};88/**89 * Show/hide custom format sections on the date-time settings page.90 */91Drupal.behaviors.dateTime = function(context) {92  // Show/hide custom format depending on the select's value.93  $('select.date-format:not(.date-time-processed)', context).change(function() {94    $(this).addClass('date-time-processed').parents("div.date-container").children("div.custom-container")[$(this).val() == "custom" ? "show" : "hide"]();95  });96  // Attach keyup handler to custom format inputs.97  $('input.custom-format:not(.date-time-processed)', context).addClass('date-time-processed').keyup(function() {98    var input = $(this);99    var url = Drupal.settings.dateTime.lookup +(Drupal.settings.dateTime.lookup.match(/\?/) ? "&format=" : "?format=") + encodeURIComponent(input.val());100    $.getJSON(url, function(data) {101      $("div.description span", input.parent()).html(data);102    });103  });104  // Trigger the event handler to show the form input if necessary.105  $('select.date-format', context).trigger('change');...wpglobus-clean.js
Source:wpglobus-clean.js  
...30			});31			$( '#wpglobus-clean-button' ).one( 'click', function(e){32				$( this ).toggleClass( 'hidden' );33				$( '#wpglobus-clean-activate' ).prop( 'checked', '' );34				api.clean();35			});	36		},	37		beforeSend: function(order){38			if ( typeof order.table !== 'undefined' ) {39				$( '#'+order.table+' .wpglobus-spinner' ).css({'visibility':'visible'});40			}	41		},42		clean: function() {43			var tables = WPGlobusClean.tables;44			45			var promise = $.when();46			47			$.each( WPGlobusClean.data, function( what, value ){48				...clean.js
Source:clean.js  
...5    return gulp.src(config.destination.css, {6      read: false,7      allowEmpty: true8    })9    .pipe(clean());10  }1112  const cleanCssRtlTask = function () {13    return gulp.src(config.destination.css_rtl, {14      read: false,15      allowEmpty: true16    })17    .pipe(clean());18  }1920  const cleanCssRtlVendorTask = function () {21    return gulp.src(config.vendors_path + 'css/vendors-rtl.min.css', {22      read: false,23      allowEmpty: true24    })25    .pipe(clean());26  }2728  const CleanDocumentationTask = function () {29    return gulp.src(config.html + '/' + myTextDirection + '/' + myLayoutName + '/*.html', {30      read: false,31      allowEmpty: true32    })33    .pipe(clean());34  }3536  const cleanHtmlTask = function () {37    return gulp.src(config.html + '/' + myTextDirection + '/' + myLayoutName + '/**/*.html', {38      read: false,39      allowEmpty: true40    })41    .pipe(clean());42  }4344  const cleanJsTask = function () {45    return gulp.src(config.destination.js, {46      read: false,47      allowEmpty: true48    })49    .pipe(clean());50  }5152  const cleanSkHtmlTask = function () {53    return gulp.src(config.starter_kit + '/' + myTextDirection + '/' + myLayoutName + '/**/*.html', {54      read: false,55      allowEmpty: true56    })57    .pipe(clean());58  }5960  // ---------------------------------------------------------------------------61  // Exports6263  return {64    css: cleanCssTask,65    css_rtl: cleanCssRtlTask,66    css_rtl_vendor: cleanCssRtlVendorTask,67    documentation: CleanDocumentationTask,68    html: cleanHtmlTask,69    js: cleanJsTask,70    sk_html: cleanSkHtmlTask71  }
...clean.task.js
Source:clean.task.js  
1const gulp = require('gulp');2const argv = require('yargs').argv;3const CleanSlate = require('../modules/CleanSlate.class');4const CleanSlateMessages = require('../modules/CleanSlateMessages.class');5/****************************************************/6/*                                                 */7/*   Clean-Slate Clean Task (clean.task.js)       */8/*                                               */9/************************************************/10/*11  - Swap out existing source files for the clean version.12  - This task primarily accesses the clean-slate module13    See module for more details (~/gulp/clean-slate/modules/CleanSlate.class.js)14  - Also refer to ~/gulp/clean-slate/README.md for more details.15  *************16  * Contents: *17  *************18  # Task19*/20/**************************************/21/*   # Task                          */22/************************************/23let taskName = 'clean';24gulp.task(taskName, gulp.series((done) => {25  let timestamp = Date.now();26  let renameMedfix = '.' + timestamp;27  let cleanSlate = new CleanSlate(renameMedfix);28  let cleanHtml = argv.html;29  let cleanCss = argv.css;30  let csMsgs = new CleanSlateMessages(taskName);31  /**32  If either html or css was flagged to be swapped out, enter the process.33  Else, log a summary of the task.34  **/35  if(cleanHtml || cleanCss){36    let cleanSlate = new CleanSlate(renameMedfix);37    csMsgs.logExecuteMessage(); // log console message before execute38    cleanSlate.execute(taskName, cleanHtml, cleanCss);39    csMsgs.logCompletionMessage(); // log console message now that task is complete40    csMsgs.logWhatsNextMessage();41  }else{42    csMsgs.logSummaryMessage(); // log a summary of what this task is supposed to do43  }44  done();...excess.js
Source:excess.js  
1'use strict';2var core = require('../core');3var torrent, raw, groupRaw;4var escapeRegex = function(string) {5  return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&');6};7core.on('setup', function (data) {8  torrent = data;9  raw = torrent.name;10  groupRaw = '';11});12core.on('part', function (part) {13  if(part.name === 'excess') {14    return;15  }16  else if(part.name === 'group') {17    groupRaw = part.raw;18  }19  // remove known parts from the excess20  raw = raw.replace(part.raw, '');21});22core.on('map', function (map) {23  torrent.map = map;24});25core.on('end', function () {26  var clean, groupPattern, episodeNamePattern;27  // clean up excess28  clean = raw.replace(/(^[-\. ]+)|([-\. ]+$)/g, '');29  clean = clean.replace(/[\(\)\/]/g, ' ');30  clean = clean.split(/\.\.+| +/).filter(Boolean);31  if(clean.length !== 0) {32    groupPattern = escapeRegex(clean[clean.length - 1] + groupRaw) + '$';33    if(torrent.name.match(new RegExp(groupPattern))) {34      core.emit('late', {35        name: 'group',36        clean: clean.pop() + groupRaw37      });38    }39    if(torrent.map && clean[0]) {40      episodeNamePattern = '{episode}' + escapeRegex(clean[0].replace(/_+$/, ''));41      if(torrent.map.match(new RegExp(episodeNamePattern))) {42        core.emit('late', {43          name: 'episodeName',44          clean: clean.shift()45        });46      }47    }48  }49  if(clean.length !== 0) {50    core.emit('part', {51      name: 'excess',52      raw: raw,53      clean: clean.length === 1 ? clean[0] : clean54    });55  }...cleanup.js
Source:cleanup.js  
1var fs = require("fs");2clean("../android");3clean("../android/dijit");4clean("../iphone");5clean("../iphone/dijit");6clean("../blackberry");7clean("../blackberry/dijit");8clean("../holodark");9clean("../holodark/dijit");10clean("../windows");11clean("../windows/dijit");12clean("../custom");13clean("../custom/dijit");14clean("../common/transitions");15clean("../common/domButtons");16// Remove css files that have a matching less file in the same folder or in common folder17function clean(folder){ 	18	var cssFiles = [];19	getFiles(folder, /.*.css$/, cssFiles);20	var lessFiles = {};21	getFiles("../common/", /.*.less$/, lessFiles);22	getFiles(folder, /.*.less$/, lessFiles);23	24	for(var i=0; i < cssFiles.length; i++){25		if(lessFiles[cssFiles[i].replace(".css", ".less")]){ 26			console.log("deleting", folder + "/" + cssFiles[i]);27			fs.unlink(folder + "/" + cssFiles[i], function(err){if(err){console.log(err);}});			28		}29	}30	31}...Using AI Code Generation
1afterEach(function () {2  if (this.currentTest.state === 'failed') {3    browser.takeScreenshot().then(function (png) {4      allure.createAttachment('Screenshot', function () {5        return new Buffer(png, 'base64')6      }, 'image/png')();7    })8  }9});10beforeEach(function () {11});Using AI Code Generation
1afterEach(function() {2  if (this.currentTest.state === 'failed') {3    browser.takeScreenshot().then(function (png) {4      allure.createAttachment('Screenshot', function () {5        return new Buffer(png, 'base64')6      }, 'image/png')();7    })8  }9});10reporterOptions: {11  allure: {12  }13},14reporterOptions: {15  allure: {16  }17},18"scripts": {19  },20"scripts": {21  },22"scripts": {23  },24"scripts": {25  },26"scripts": {27  },28"scripts": {29  },30"scripts": {31  },Using AI Code Generation
1const { expect } = require('chai');2const { clean } = require('mocha');3const { describe } = require('mocha');4const { it } = require('mocha');5const calculator = require('./calculator');6clean();7describe('calculator', () => {8    describe('add', () => {9        it('should add two numbers', () => {10            const result = calculator.add(1, 2);11            expect(result).to.equal(3);12        });13    });14    describe('subtract', () => {15        it('should subtract two numbers', () => {16            const result = calculator.subtract(1, 2);17            expect(result).to.equal(-1);18        });19    });20    describe('multiply', () => {21        it('should multiply two numbers', () => {22            const result = calculator.multiply(1, 2);23            expect(result).to.equal(2);24        });25    });26    describe('divide', () => {27        it('should divide two numbers', () => {28            const result = calculator.divide(1, 2);29            expect(result).to.equal(0.5);30        });31    });32    describe('pow', () => {33        it('should raise a number to a power', () => {34            const result = calculator.pow(2, 3);35            expect(result).to.equal(8);36        });37    });38    describe('sqrt', () => {39        it('should take the square root of a number', () => {40            const result = calculator.sqrt(9);41            expect(result).to.equal(3);42        });43    });44    describe('sin', () => {45        it('should take the sine of an angle', () => {46            const result = calculator.sin(0);47            expect(result).to.equal(0);48        });49    });50    describe('cos', () => {51        it('should take the cosine of an angle', () => {52            const result = calculator.cos(0);53            expect(result).to.equal(1);54        });55    });56    describe('tan', () => {57        it('should take the tangent of an angle', () => {58            const result = calculator.tan(0);59            expect(result).to.equal(0);60        });61    });62    describe('log', () => {63        it('should takeUsing AI Code Generation
1afterEach(function(done) {2  done();3});4afterEach(function() {5});6### `beforeEach(fn)`7beforeEach(function(done) {8  done();9});10beforeEach(function() {11});12### `it(title, fn)`13it('should work', function(done) {14  done();15});16it('should work', function() {17});18### `it.only(title, fn)`19it.only('should work', function(done) {20  done();21});22it.only('should work', function() {23});24### `it.skip(title, fn)`25it.skip('should work', function(done) {26  done();27});28it.skip('should work', function() {29});30### `describe(title, fn)`31describe('My suite', function(done) {32  done();33});Using AI Code Generation
1const mocha = require('mocha');2const { expect } = require('chai');3const { clean } = require('../src/clean');4describe('clean', () => {5    it('should clean a string', () => {6        expect(clean('  hello world')).to.equal('hello world');7    });8});9const clean = (str) => {10    return str.trim();11};12module.exports = {13};Using AI Code Generation
1const {clean} = require('mocha-clean');2describe('Test', () => {3  beforeEach(clean);4  it('Should clean the console', () => {5    console.log('Hello');6  });7});8const {clean} = require('mocha-clean');9describe('Test', () => {10  beforeEach(clean);11  it('Should clean the console', () => {12    console.log('Hello');13  });14  it('Should clean the console', () => {15    console.log('Hello');16  });17});18const {clean} = require('mocha-clean');19describe('Test', () => {20  beforeEach(clean);21  it('Should clean the console', () => {22    console.log('Hello');23  });24  it('Should clean the console', () => {25    console.log('Hello');26  });27  it('Should clean the console', () => {28    console.log('Hello');29  });30});31const {clean} = require('mocha-clean');32describe('Test', () => {33  beforeEach(clean);34  it('Should clean thUsing AI Code Generation
1afterEach(function () {2    console.log('After each');3    clean();4});5after(function () {6    console.log('After');7    clean();8});9beforeEach(function () {10    console.log('Before each');11    clean();12});13before(function () {14    console.log('Before');15    clean();16});17afterEach(function () {18    console.log('After each');19    clean();20});21after(function () {22    console.log('After');23    clean();24});25beforeEach(function () {26    console.log('Before each');27    clean();28});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!!
