Best JavaScript code snippet using mocha
pending.spec.js
Source:pending.spec.js
...292 invokeNode([path], function(err, res) {293 if (err) {294 return done(err);295 }296 var result = toJSONResult(res);297 expect(result, 'to have passed')298 .and('to have passed test count', 0)299 .and('to have pending test count', 1)300 .and('to have pending test order', 'should succeed');301 done();302 });303 });304 });...
pmdetail.js
Source:pmdetail.js
1function getContById(){2 var url= _ctx + "/cont/cont-ledger!input.action?id="+$("#contLedgerId").val();3 $.post(url,{}, function(result){4 if(parent.TabUtils==null)5 window.open(url);6 else7 parent.TabUtils.newTab("cont-ledger-input","ååå°è´¦æ¥ç",url,true);8 });9 10}11//å¤ææ¯å¦ä¸ºç©º12function validatePm(){13 //ä¼åæ¡ä¾ç¼å·14 var pmMateEntryNo = $("#pmMateEntryNo");15 if(""==pmMateEntryNo.val()){16 alert("ä¼åæ¡ä¾ç¼å·ä¸ºå¿
å¡«");17 pmMateEntryNo.focus();18 return false;19 }20 //æ´»å¨ä¸»é¢21 var activeTitle = $("#activeTitle");22 if(""==activeTitle.val()){23 alert("æ´»å¨ä¸»é¢ä¸ºå¿
å¡«");24 activeTitle.focus();25 return false;26 }27 //æ´»å¨å
容28 var activeContent = $("#activeContent");29 if(""==activeContent.val()){30 alert("æ´»å¨å
容为å¿
å¡«");31 activeContent.focus();32 return false;33 }34 //æ¶é´å¨æ35 var activePeriod = $("#activePeriod");36 if(""==activePeriod.val()){37 alert("æ¶é´å¨æ为å¿
å¡«");38 activePeriod.focus();39 return false;40 }41 //è´¹ç¨é¢æ42 var expensesBudget = $("#expensesBudget");43 if(""==expensesBudget.val()){44 alert("è´¹ç¨é¢æ为å¿
å¡«");45 expensesBudget.focus();46 return false;47 }48 //éå
·49 var properties = $("#properties");50 if(""==properties.val()){51 alert("éå
·ä¸ºå¿
å¡«");52 properties.focus();53 return false;54 }55 //ç¾é56 var meiChen = $("#meiChen");57 if(""==meiChen.val()){58 alert("ç¾é为å¿
å¡«");59 meiChen.focus();60 return false;61 }62 //èµ å63 var present = $("#present");64 if(""==present.val()){65 alert("èµ å为å¿
å¡«");66 present.focus();67 return false;68 }69 //åªä½70 var medium = $("#medium");71 if(""==medium.val()){72 alert("åªä½ä¸ºå¿
å¡«");73 medium.focus();74 return false;75 }76 //æä½æå¼77 var operatorGuide = $("#operatorGuide");78 if(""==operatorGuide.val()){79 alert("æä½æ导为å¿
å¡«");80 operatorGuide.focus();81 return false;82 }83 //é¢æææ84 var expectedResults = $("#expectedResults");85 if(""==expectedResults.val()){86 alert("é¢æææ为å¿
å¡«");87 expectedResults.focus();88 return false;89 }90 //åèå¾ç91 var attaFilesContainer = $("#attaFilesContainer").find(".mainTr");92 if(""==attaFilesContainer.text()){93 alert("请å
ä¸ä¼ åèå¾çåæ¹æ¡");94 return false;95 }96 return true;97}98//ä¿åä¼åæ¡ä¾åº99function savePmMateEntry(){100 //ä¼åæ¡ä¾ç¼å·101 var pmMateEntryNo = $("#pmMateEntryNo");102 var pmMateEntryId = $("#pmMateEntryId");103 var flag = $("#flag").val();104 //ç»è®¡ææé件ä¸çæ件æ°105 var objLen = $("#attaFilesContainer").find(".mainTr").length;106 //ç»è®¡é件é¢è§ä¸çå¾çæ°107 var objImgLen = $("#attaFilesContainer").find("a img").length;108 //ç»è®¡é¤å¾çå¤å
¶ä»æ ¼å¼æ件æ°109 var objFilesLen = parseInt(objLen)-parseInt(objImgLen);110 //alert("objLen: "+objLen+" ,objImgLen: "+objImgLen+" ,objFilesLen: "+objFilesLen);111 //if(objImgLen>0){112 // $("#fileSn_pic").val("1");113 //}else{114 // $("#fileSn_pic").val("0");115 //}116 //if(objFilesLen>0){117 // $("#fileSn_prj").val("1");118 //}else{119 // $("#fileSn_prj").val("0");120 //}121 if(objLen>0){122 $("#fileSn_pic").val("1");123 }else{124 $("#fileSn_pic").val("0");125 }126 if(validatePm()==true){127 var url= _ctx + "/pm/pm-mate-entry!noRepeat.action";128 var param={pmMateEntryNo:$.trim(pmMateEntryNo.val())};129 if(flag=="0"){130 var pmEntryNo_U = $.trim($("#pmMateEntryNo").attr("pmEntryNo_U"));131 //alert(pmEntryNo_U+" || "+pmMateEntryNo.val());132 $.post(url,param,function(result){133 //alert((pmEntryNo_U==$.trim(pmMateEntryNo.val()))+" pmEntryId : "+$("#pmEntryId").val()+" pmMateEntryId: "+$("#pmMateEntryId").val()+" pmMateModuId: "+$("#pmMateModuId").val());134 if(pmEntryNo_U==$.trim(pmMateEntryNo.val())){135 TB_showMaskLayer("æ£å¨ä¿å...");136 $("#pmMateEntryFrom").ajaxSubmit(function(result){137 var toJsonResult = eval("("+result+")");138 if("success"==toJsonResult.status){139 openTipSuccess("ä¿åæå");140 doQueryMateById($("#pmMateModuId").val());141 }else{142 openTipFailure("ä¿å失败");143 return false;144 } 145 });146 TB_removeMaskLayer();147 }else{148 if($.trim(result)!=''){149 alert("ä¼åæ¡ä¾ç¼å·å·²ç»åå¨");150 pmMateEntryNo.focus();151 return false;152 }else{153 TB_showMaskLayer("æ£å¨ä¿å...");154 //alert("save ... pmMateEntryId:"+$("#pmMateEntryId").val());155 $("#pmMateEntryFrom").ajaxSubmit(function(result){156 var toJsonResult = eval("("+result+")");157 //alert(toJsonResult.status+" "+toJsonResult.pmMateEntryId);158 if("success"==toJsonResult.status){159 openTipSuccess("ä¿åæå");160 //alert(toJsonResult.pmMateEntryId);161 $("#pmEntryId").val(toJsonResult.pmMateEntryId);162 $("#pmMateModuId").val(toJsonResult.pmMateModuId);163 $("#pmMateEntryId").val(toJsonResult.pmMateEntryId);164 $("#pmMateEntryNo").attr("pmEntryNo_U",toJsonResult.pmMateEntryNo);165 166 var id = toJsonResult.pmMateEntryId;167 //updateMateEntry(id);168 doQueryMateById($("#pmMateModuId").val());169 }else{170 openTipFailure("ä¿å失败");171 return false;172 } 173 });174 TB_removeMaskLayer();175 }176 }177 });178 }else{179 var pmEntryNo_U = $.trim($("#pmMateEntryNo").attr("pmEntryNo_U"));180 $.post(url,param,function(result){181 //alert(pmEntryNo_U==$.trim(pmMateEntryNo.val()));182 if(pmEntryNo_U==$.trim(pmMateEntryNo.val())){183 TB_showMaskLayer("æ£å¨ä¿å...");184 $("#pmMateEntryFrom").ajaxSubmit(function(result){185 var toJsonResult = eval("("+result+")");186 if("success"==toJsonResult.status){187 openTipSuccess("ä¿®æ¹æå");188 $("#flag").val("1");189 doQueryMateById($("#pmMateModuId").val());190 }else{191 openTipFailure("ä¿®æ¹å¤±è´¥");192 return false;193 } 194 });195 TB_removeMaskLayer();196 }else{197 if($.trim(result)!=''){198 alert("ä¼åæ¡ä¾ç¼å·å·²ç»åå¨");199 pmMateEntryNo.focus();200 return false;201 }else{202 TB_showMaskLayer("æ£å¨ä¿å...");203 $("#pmMateEntryFrom").ajaxSubmit(function(result){204 var toJsonResult = eval("("+result+")");205 if("success"==toJsonResult.status){206 openTipSuccess("ä¿®æ¹æå");207 $("#flag").val("1");208 doQueryMateById($("#pmMateModuId").val());209 }else{210 openTipFailure("ä¿®æ¹å¤±è´¥");211 return false;212 } 213 });214 TB_removeMaskLayer();215 }216 }217 });218 }219 }220}221/**222 * æ¾ç¤ºæ示æå223 * @param result224 */225function openTipSuccess(result){226 var myDate = new Date();227 var hour = myDate.getHours(); //è·åå½åå°æ¶æ°(0-23)228 var minu = myDate.getMinutes(); //è·åå½ååéæ°(0-59)229 var sec = myDate.getSeconds(); //è·åå½åç§æ°(0-59)230 $('#operateTip').html(hour +':' + minu + ':' + sec +' ' + result).css({'color':'green'}).show().fadeOut(5000);231}232/**233 * æ¾ç¤ºæ示ä¸æå234 * @param result235 */236function openTipFailure(result){237 $('#operateTip').css({'color':'red'}).html(result).show().fadeOut(5000);...
calendar.spec.js
Source:calendar.spec.js
1const proxyquire = require('proxyquire').noCallThru();2describe('handlers: calendar', () => {3 describe('insertNewRecord', () => {4 it('should resolve with new record object', async () => {5 const test = {6 recordInfo: {7 name: 'Alanis Simonis',8 email: 'alanis_simonis1959@example.com',9 date: '31.12.1979',10 status: 'remoteWork',11 isDeleted: false,12 note: '',13 period: 8,14 },15 user: {16 name: 'Alanis Simonis',17 email: 'alanis_simonis1959@example.com',18 },19 workerHours: 0,20 toJSONResult: {21 _id: '123',22 name: 'Alanis Simonis',23 email: 'alanis_simonis1959@example.com',24 date: '31.12.1979',25 status: 'remoteWork',26 isDeleted: false,27 note: '',28 period: 8,29 },30 };31 const expected = {32 result: {33 _id: '123',34 name: 'Alanis Simonis',35 email: 'alanis_simonis1959@example.com',36 date: '31.12.1979',37 status: 'remoteWork',38 isDeleted: false,39 note: '',40 period: 8,41 },42 userStatParams: {43 email: 'alanis_simonis1959@example.com',44 date: new Date('12.31.1979'),45 },46 saveNewRecordParams: {47 __v: 0,48 name: 'Alanis Simonis',49 email: 'alanis_simonis1959@example.com',50 date: new Date('12.31.1979'),51 status: 'remoteWork',52 isDeleted: false,53 note: '',54 period: 8,55 },56 userQuery: {57 email: 'alanis_simonis1959@example.com',58 },59 };60 const calendarHandler = proxyquire('handlers/calendar', {61 'models/calendar': {62 getSingleUserStat: async (params) => {63 expect(params).to.be.deep.equal(expected.userStatParams);64 return test.workerHours;65 },66 saveNewRecord: async (recordInfo) => {67 expect(recordInfo).to.be.deep.equal(expected.saveNewRecordParams);68 return {69 toJSON: () => test.toJSONResult,70 };71 },72 },73 'handlers/users': {74 findUser: async (params) => {75 expect(params).to.be.deep.equal(expected.userQuery);76 return test.user;77 },78 },79 });80 await expect(calendarHandler.insertNewRecord(test.recordInfo))81 .to.eventually.be.deep.equal(expected.result);82 });83 });84 describe('getStat', () => {85 it('should resolve with correct statistic', async () => {86 const test = {87 params: {88 from: '31.12.1979',89 to: '31.12.1989',90 emails: JSON.stringify(['test1@test.test', 'test2@test.test']),91 },92 getStatisticOutput: [{93 name: 'Ivan Smirnov',94 email: 'test1@test.test',95 pediods: [{96 status: 'work',97 days: 10,98 }],99 }, {100 name: 'Ivan Smirnov',101 email: 'test2@test.test',102 pediods: [{103 status: 'work',104 days: 10,105 }],106 }],107 };108 const expected = {109 result: [{110 name: 'Ivan Smirnov',111 email: 'test1@test.test',112 pediods: [{113 status: 'work',114 days: 10,115 }],116 }, {117 name: 'Ivan Smirnov',118 email: 'test2@test.test',119 pediods: [{120 status: 'work',121 days: 10,122 }],123 }],124 getStatisticInput: {125 date: {126 $gte: new Date('12.31.1979'),127 $lte: new Date('12.31.1989'),128 },129 email: {130 $in: ['test1@test.test', 'test2@test.test'],131 },132 },133 };134 const calendarHandler = proxyquire('handlers/calendar', {135 'models/calendar': {136 getStatistic: async (query) => {137 expect(query).to.be.deep.equal(expected.getStatisticInput);138 return test.getStatisticOutput;139 },140 },141 'handlers/users': {},142 });143 await expect(calendarHandler.getStat(test.params))144 .to.eventually.be.deep.equal(expected.result);145 });146 });...
subscriptionsSpec.js
Source:subscriptionsSpec.js
1const expect = require('chai').expect;2const Subscriptions = require('../../core/subscriptions');3const uuid = require('node-uuid').v4;4describe('Subscriptions', function(){5 afterEach(() => {6 Subscriptions.removeAll();7 });8 describe('#createSubscription', function(){9 it('should create new subscription', function(){10 const subscriber = uuid();11 Subscriptions.createSubscription(subscriber, uuid());12 expect(Subscriptions.getSubscriptionBySubscriberId(subscriber)).to.have.length(1);13 });14 });15 describe('#getSubscriptionBySubscriberId', function(){16 it('should return subscriptions', function(){17 const subscriber = uuid();18 Subscriptions.createSubscription(subscriber, uuid());19 expect(Subscriptions.getSubscriptionBySubscriberId(subscriber)).to.have.length(1);20 });21 });22 describe('#getSubscriptionBySubscribeToId', function(){23 it('should return subscriptions', function(){24 const subscriber = uuid();25 const subscribeTo = uuid();26 Subscriptions.createSubscription(subscriber, subscribeTo);27 expect(Subscriptions.getSubscriptionBySubscribeToId(subscribeTo)).to.have.length(1);28 });29 });30 describe('#removeSubscriptionById', function(){31 it('should remove subscription', function(){32 const subscriber = uuid();33 const subscription = Subscriptions.createSubscription(subscriber, uuid());34 Subscriptions.removeSubscriptionById(subscription.id);35 expect(Subscriptions.getSubscriptionBySubscriberId(subscriber)).to.have.length(0);36 });37 it('should not remove subscription if none', function(){38 Subscriptions.removeSubscriptionById(uuid());39 expect(Subscriptions.getSubscriptionBySubscriberId(uuid())).to.have.length(0);40 });41 });42 describe('#removeSubscriptionBySubscriberId', function(){43 it('should remove subscription', function(){44 const subscriber = uuid();45 Subscriptions.createSubscription(subscriber, uuid());46 Subscriptions.removeSubscriptionBySubscriberId(subscriber);47 expect(Subscriptions.getSubscriptionBySubscriberId(subscriber)).to.have.length(0);48 });49 it('should not remove subscription if none', function(){50 Subscriptions.removeSubscriptionBySubscriberId(uuid());51 expect(Subscriptions.getSubscriptionBySubscriberId(uuid())).to.have.length(0);52 });53 });54 describe('#removeAll', function(){55 it('should remove all subscriptions', function(){56 const subscriber = uuid();57 Subscriptions.createSubscription(uuid(), uuid());58 Subscriptions.createSubscription(subscriber, uuid());59 Subscriptions.createSubscription(subscriber, uuid());60 Subscriptions.createSubscription(uuid(), uuid());61 Subscriptions.createSubscription(uuid(), uuid());62 Subscriptions.removeAll();63 expect(Subscriptions.getSubscriptionBySubscriberId(subscriber)).to.have.length(0);64 });65 });66 describe('#toJSON', function(){67 it('should return subscription without ws property', function(){ 68 let subscription = Subscriptions.createSubscription(uuid(), uuid(), {});69 let toJsonResult = subscription.toJSON();70 expect(toJsonResult.ws).to.be.undefined;71 });72 });...
enhance-stringify.js
Source:enhance-stringify.js
1var json = typeof JSON !== 'undefined' ? JSON : require('jsonify');2module.exports = function (obj, opts) {3 if (!opts) opts = {};4 if (typeof opts === 'function') opts = { cmp: opts };5 var space = opts.space || '';6 if (typeof space === 'number') space = Array(space+1).join(' ');7 var cycles = (typeof opts.cycles === 'boolean') ? opts.cycles : false;8 var replacer = opts.replacer || function(key, value) { return value; };9 var toJSONStr = opts.toJSONStr || function(key, value) { return undefined; };10 var cmp = opts.cmp && (function (f) {11 return function (node) {12 return function (a, b) {13 var aobj = { key: a, value: node[a] };14 var bobj = { key: b, value: node[b] };15 return f(aobj, bobj);16 };17 };18 })(opts.cmp);19 var seen = [];20 return (function stringify (parent, key, node, level) {21 var indent = space ? ('\n' + new Array(level + 1).join(space)) : '';22 var colonSeparator = space ? ': ' : ':';23 if (node && node.toJSON && typeof node.toJSON === 'function') {24 node = node.toJSON();25 }26 node = replacer.call(parent, key, node);27 let toJSONResult = toJSONStr.call(parent, key, node);28 if (!!toJSONResult) {29 return toJSONResult;30 }31 if (node === undefined) {32 return;33 }34 if (typeof node !== 'object' || node === null) {35 return json.stringify(node);36 }37 if (isArray(node)) {38 var out = [];39 for (var i = 0; i < node.length; i++) {40 var item = stringify(node, i, node[i], level+1) || json.stringify(null);41 out.push(indent + space + item);42 }43 return '[' + out.join(',') + indent + ']';44 }45 else {46 if (seen.indexOf(node) !== -1) {47 if (cycles) return json.stringify('__cycle__');48 throw new TypeError('Converting circular structure to JSON');49 }50 else seen.push(node);51 var keys = objectKeys(node).sort(cmp && cmp(node));52 var out = [];53 for (var i = 0; i < keys.length; i++) {54 var key = keys[i];55 var value = stringify(node, key, node[key], level+1);56 if(!value) continue;57 var keyValue = json.stringify(key)58 + colonSeparator59 + value;60 ;61 out.push(indent + space + keyValue);62 }63 seen.splice(seen.indexOf(node), 1);64 return '{' + out.join(',') + indent + '}';65 }66 })({ '': obj }, '', obj, 0);67};68var isArray = Array.isArray || function (x) {69 return {}.toString.call(x) === '[object Array]';70};71var objectKeys = Object.keys || function (obj) {72 var has = Object.prototype.hasOwnProperty || function () { return true };73 var keys = [];74 for (var key in obj) {75 if (has.call(obj, key)) keys.push(key);76 }77 return keys;...
document-test.js
Source:document-test.js
1import Schema from 'ember-json-schema-document/models/schema';2import Document from 'ember-json-schema-document/models/document';3import { module, test, skip } from 'qunit';4import schemaFixture from '../../fixtures/default-nested-property-schema';5module('models/document', {6 beforeEach() {7 this.schema = new Schema(schemaFixture);8 this.document = this.schema.buildDocument();9 }10});11test('requires a schema', function(assert) {12 assert.throws(function() {13 new Document();14 }, /You must provide a Schema instance to the Document constructor/);15});16test('dump and toJSON return equal values', function(assert) {17 this.document.set('address.streetAddress', '123 Blah St.');18 this.document.set('address.city', 'Hope');19 let dumpResult = this.document.dump();20 let toJSONResult = this.document.toJSON();21 assert.deepEqual(dumpResult, {22 address: {23 streetAddress: '123 Blah St.',24 city: 'Hope'25 }26 });27 assert.deepEqual(toJSONResult, {28 address: {29 streetAddress: '123 Blah St.',30 city: 'Hope'31 }32 });33 assert.deepEqual(toJSONResult, dumpResult);34});35test('serialize skips null and undefined values', function(assert) {36 this.document.set('address.streetAddress', null);37 this.document.set('address.city', 'San Diego');38 let dumpResult = this.document.dump();39 assert.deepEqual(dumpResult, { address: { city: 'San Diego' } });40});41skip('throw an error if calling `dump` when required fields are not specified');42skip('handle array properties (where you have many of a given item)');...
extension.spec.js
Source:extension.spec.js
...18 invokeMocha(args, function(err, res) {19 if (err) {20 return done(err);21 }22 expect(toJSONResult(res), 'to have passed').and(23 'to have passed test count',24 225 );26 done();27 });28 });29 it('should allow extensions beginning with a dot', function(done) {30 var args = [31 '--require',32 'coffee-script/register',33 '--require',34 './test/setup',35 '--reporter',36 'json',37 '--extension',38 '.js',39 'test/integration/fixtures/options/extension'40 ];41 invokeMocha(args, function(err, res) {42 if (err) {43 return done(err);44 }45 expect(toJSONResult(res), 'to have passed').and(46 'to have passed test count',47 148 );49 done();50 });51 });...
index.test.js
Source:index.test.js
1import path from 'path';2import fs from 'fs';3import genDiff from '../src/index.js';4const getFixturePath = (filename) => path.join(__dirname, '__fixtures__', filename);5const readFixtureFile = (filename) => fs.readFileSync(getFixturePath(filename), 'utf8');6const compareFiles = (firstFile, secondFile, format) => {7 const pathToFirstFile = getFixturePath(firstFile);8 const pathToSecondFile = getFixturePath(secondFile);9 const difference = genDiff(pathToFirstFile, pathToSecondFile, format);10 return difference;11};12const stylishResult = readFixtureFile('stylish.txt');13const plainResult = readFixtureFile('plain.txt');14const toJSONresult = readFixtureFile('toJSON.txt');15describe('test all formatters', () => {16 test.each([17 ['before.json', 'after.json', 'stylish', stylishResult],18 ['before.yml', 'after.yaml', 'plain', plainResult],19 ['before.ini', 'after.ini', 'json', toJSONresult],20 ])('compare %s and %s', (firstFile, secondFile, format, expected) => {21 expect(compareFiles(firstFile, secondFile, format)).toBe(expected);22 });...
Using AI Code Generation
1var Mocha = require('mocha');2var mocha = new Mocha({reporter: 'json'});3mocha.addFile('test1.js');4mocha.run(function(failures){5 process.on('exit', function () {6 });7}).on('test end', function(test){8 console.log(JSON.stringify(test));9}).on('end', function(){10 console.log('end');11});12var assert = require('assert');13describe('Array', function(){14 describe('#indexOf()', function(){15 it('should return -1 when the value is not present', function(){16 assert.equal(-1, [1,2,3].indexOf(5));17 assert.equal(-1, [1,2,3].indexOf(0));18 });19 });20});21{"title":"should return -1 when the value is not present","fullTitle":"Array #indexOf() should return -1 when the value is not present","timedOut":false,"duration":0,"state":"failed","speed":"fast","pass":false,"fail":true,"pending":false,"code":"assert.equal(-1, [1,2,3].indexOf(5));","err":{"message":"expected 0 to equal -1","showDiff":true,"actual":0,"expected":-1,"stack":"AssertionError: expected 0 to equ
Using AI Code Generation
1var mocha = require('mocha');2var assert = require('chai').assert;3var expect = require('chai').expect;4var should = require('chai').should();5var chai = require('chai');6var chaiHttp = require('chai-http');7var server = require('../index.js');8var mongoose = require('mongoose');9var User = require('../models/user');10var jwt = require('jsonwebtoken');11var config = require('../config');12var async = require('async');13var _ = require('lodash');14var request = require('supertest');15var agent = request.agent(server);16var app = require('../index.js');17var http = require('http');18var server = http.createServer(app);19var io = require('socket.io-client');20var options ={21};22var socket = io.connect(socketURL,options);23var token;24var user;25var user2;26var user3;27var user4;28var user5;29var user6;30var user7;31var user8;32var user9;33var user10;34var user11;35var user12;36var user13;37var user14;38var user15;39var user16;40var user17;41var user18;42var user19;43var user20;44var user21;45var user22;46var user23;47var user24;48var user25;49var user26;50var user27;51var user28;52var user29;53var user30;54var user31;55var user32;56var user33;57var user34;58var user35;59var user36;60var user37;61var user38;62var user39;63var user40;64var user41;65var user42;66var user43;67var user44;68var user45;69var user46;70var user47;71var user48;72var user49;73var user50;74var user51;75var user52;76var user53;77var user54;78var user55;79var user56;80var user57;81var user58;82var user59;83var user60;84var user61;85var user62;86var user63;87var user64;88var user65;89var user66;90var user67;91var user68;92var user69;93var user70;94var user71;95var user72;96var user73;97var user74;98var user75;99var user76;100var user77;
Using AI Code Generation
1var assert = require('assert');2var mocha = require('mocha');3var expect = require('chai').expect;4var should = require('chai').should();5var chai = require('chai');6var chaiHttp = require('chai-http');7var server = require('../server.js');8var sinon = require('sinon');9var sinonChai = require('sinon-chai');10var request = require('request');11var fs = require('fs');12var path = require('path');13var mongoose = require('mongoose');14chai.use(chaiHttp);15chai.use(sinonChai);16var User = require('../server/models/user');17var user = new User();18var db = mongoose.connection;19describe('User', function() {20 before(function(done) {21 var db = mongoose.connection;22 db.on('error', console.error.bind(console, 'connection error:'));23 db.once('open', function() {24 console.log('Connected to database');25 done();26 });27 });28 after(function(done) {29 mongoose.connection.db.dropDatabase(function() {30 mongoose.connection.close(done);31 });32 });33 describe('GET /', function() {34 it('should return 200 status code', function(done) {35 chai.request(server)36 .get('/')37 .end(function(err, res) {38 expect(res).to.have.status(200);39 done();40 });41 });42 it('should return a text/html content-type', function(done) {43 chai.request(server)44 .get('/')45 .end(function(err, res) {46 expect(res).to.have.header('content-type', 'text/html; charset=utf-8');47 done();48 });49 });50 });51 describe('POST /', function() {52 it('should return 200 status code', function(done) {53 chai.request(server)54 .post('/')55 .end(function(err, res) {56 expect(res).to.have.status(200);57 done();58 });59 });60 it('should return a text/html content-type', function(done) {61 chai.request(server)62 .post('/')63 .end(function(err, res) {64 expect(res).to.have.header('content-type', 'text/html; charset=utf-8');65 done();66 });67 });68 });69 describe('POST /login', function() {70 it('should return 200 status code', function
Using AI Code Generation
1var mocha = require('mocha');2var assert = require('chai').assert;3var expect = require('chai').expect;4describe('Test', function() {5 it('should return true', function() {6 expect(true).to.be.true;7 });8});9var Mocha = require('mocha');10var mocha = new Mocha();11mocha.addFile('./test.js');12mocha.run(function(failures) {13 process.on('exit', function() {14 });15});16var Mocha = require('mocha');17var mocha = new Mocha();18mocha.addFile('./test.js');19mocha.run(function(failures) {20 process.on('exit', function() {21 });22}).on('test', function(test) {23 console.log('Test started: ' + test.title);24}).on('test end', function(test) {25 console.log('Test done: ' + test.title);26}).on('pass', function(test) {27 console.log('Test passed: ' + test.title);28}).on('fail', function(test, err) {29 console.log('Test failed: ' + test.title + ' err: ' + err.message);30}).on('end', function() {31 console.log('All done');32});
Using AI Code Generation
1var mocha = require('mocha');2var fs = require('fs');3 mocha = new Mocha();4mocha.addFile('./test.js');5mocha.run(function(failures){6 process.on('exit', function () {7 });8}).on('end', function(){9 var json = mocha.toJSONResult();10 fs.writeFileSync('test.json', JSON.stringify(json));11});12{13 "stats": {14 },15 {16 "err": {17 "stack": "AssertionError: expected 'Hello World!' to equal 'Hello World'\n at Context.<anonymous> (test.js:10:29)\n at callFn (node_modules/mocha/lib/runnable.js:334:21)\n at Test.Runnable.run (node_modules/mocha/lib/runnable.js:327:7)\n at Runner.runTest (node_modules/mocha/lib/runner.js:429:10)\n at node_modules/mocha/lib/runner.js:535:12\n at next (node_modules/mocha/lib/runner.js:349:14)\n at node_modules/mocha/lib/runner.js:359:7\n at next (node_modules/mocha/lib/runner.js:295:14)\n at Immediate.<anonymous> (node_modules/mocha
Using AI Code Generation
1var Mocha = require('mocha');2var mocha = new Mocha();3var fs = require('fs');4var path = require('path');5fs.readdirSync('test').filter(function(file){6 return file.substr(-3) === '.js';7}).forEach(function(file){8 mocha.addFile(9 path.join('test', file)10 );11});12mocha.run(function(failures){13 process.on('exit', function () {14 });15}).on('end', function() {16 var results = mocha.testResults;17 var jsonResult = results.toJSONResult();18 console.log(JSON.stringify(jsonResult));19});20var exec = require('child_process').exec;21var cmd = 'mocha --reporter json test.js';22exec(cmd, function(error, stdout, stderr) {23 console.log(stdout);24});25{26 "stats": {27 },28 {29 }30}31var exec = require('child_process').exec;32var cmd = 'mocha --reporter json test.js';33exec(cmd, function(error,
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!!