Best JavaScript code snippet using mocha
caching.js
Source:caching.js
...12 jsdoc.cache.dir = 'tmp/cache-sync'13 return jsdoc.cache.clear()14 .then(() => {15 const output = jsdoc.explainSync({ files: f.sourcePath, cache: true })16 const expectedOutput = f.getExpectedOutput(output)17 a.ok(typeof output === 'object')18 a.deepEqual(output, expectedOutput)19 })20})21runner.test('caching: .explain({ files, cache: true })', function () {22 const f = new Fixture('class-all')23 jsdoc.cache.dir = 'tmp/cache'24 return jsdoc.cache.clear()25 .then(() => {26 return jsdoc.explain({ files: f.sourcePath, cache: true })27 .then(output => {28 const cachedFiles = fs.readdirSync(jsdoc.cache.dir)29 .map(file => path.resolve(jsdoc.cache.dir, file))30 a.strictEqual(cachedFiles.length, 1)31 a.deepEqual(output, f.getExpectedOutput(output))32 const cachedData = JSON.parse(fs.readFileSync(cachedFiles[0], 'utf8'))33 Fixture.removeFileSpecificData(cachedData)34 a.deepEqual(35 cachedData,36 f.getExpectedOutput(output)37 )38 })39 })40})41runner.test('caching: .explain({ source, cache: true }) - Ensure correct output (#147)', function () {42 return jsdoc.cache.clear().then(() => {43 let one = jsdoc.explain({ source: '/**\n * Function one\n */\nfunction one () {}\n', cache: true })44 let two = jsdoc.explain({ source: '/**\n * Function two\n */\nfunction two () {}\n', cache: true })45 let three = jsdoc.explain({ source: '/**\n * Function three\n */\nfunction three () {}\n', cache: true })46 Promise.all([ one, two, three ]).then(output => {47 a.strictEqual(output[0][0].description, 'Function one')48 a.strictEqual(output[1][0].description, 'Function two')49 a.strictEqual(output[2][0].description, 'Function three')50 })...
test.js
Source:test.js
...7 let fixturePath = path.join(process.cwd(), 'test', 'fixtures', fixture);8 process.chdir(fixturePath);9 execSync('../../../bin/lego b');10}11function getExpectedOutput() {12 return JSON.parse(fs.readFileSync('expected-output.json'));13}14function getCurrentOutput() {15 return fixturify.readSync('build');16}17describe('lego', function() {18 this.timeout(60 * 1000);19 afterEach(() => {20 process.chdir('../../../');21 });22 describe('build', function() {23 it('should build the project with cache disabled', async function() {24 process.env.SKIP_CACHE = 'true';25 runLego('dummy');26 let expectedOutput = getExpectedOutput();27 let actualOutput = getCurrentOutput();28 assert.deepStrictEqual(expectedOutput, actualOutput);29 });30 it('should build the project with cache enabled', async function() {31 delete process.env.SKIP_CACHE;32 runLego('dummy');33 let expectedOutput = getExpectedOutput();34 let actualOutput = getCurrentOutput();35 assert.deepStrictEqual(expectedOutput, actualOutput);36 });37 it('should build the project with a pre-existing cache', async function() {38 delete process.env.SKIP_CACHE;39 runLego('dummy');40 let expectedOutput = getExpectedOutput();41 let actualOutput = getCurrentOutput();42 assert.deepStrictEqual(expectedOutput, actualOutput);43 // build again with cache44 execSync('../../../bin/lego b');45 actualOutput = getCurrentOutput();46 assert.deepStrictEqual(expectedOutput, actualOutput);47 });48 it('should build the project with categories in posts enabled', async function() {49 runLego('categories');50 let expectedOutput = getExpectedOutput();51 let actualOutput = getCurrentOutput();52 assert.deepStrictEqual(expectedOutput, actualOutput);53 });54 it('should build the project with categories in posts disabled', async function() {55 runLego('no-categories');56 let expectedOutput = getExpectedOutput();57 let actualOutput = getCurrentOutput();58 assert.deepStrictEqual(expectedOutput, actualOutput);59 });60 });...
loader.test.js
Source:loader.test.js
...29availableFileSyntaxes.forEach((syntax) => {30 test(`Outputs custom properties object for ${syntax.toUpperCase()}`, async () => {31 const stats = await compiler(`example.${syntax}`, { syntax });32 const output = stats.toJson({ source: true }).modules[0].source;33 expect(output).toBe(`module.exports = ${getExpectedOutput(syntax)}`);34 });35 test(`Outputs unprefixed custom properties object for ${syntax.toUpperCase()}`, async () => {36 const prefix = false;37 const stats = await compiler(`example.${syntax}`, { syntax, prefix });38 const output = stats.toJson({ source: true }).modules[0].source;39 expect(output).toBe(`module.exports = ${getExpectedOutput(syntax, prefix)}`);40 });...
general.test.js
Source:general.test.js
...9 expect(output).toStrictEqual(getExpectedFile('01-help-switch/console.txt'));10});11test('02 simple passtrough', async () => {12 await execute(['-c', 'config/02-simple-pass.yaml']);13 expect(getExpectedOutput('02-simple-pass')).toStrictEqual(getProducedOutput());14});15test('03 multiple passtrough with extended from and to', async () => {16 await execute(['-c', 'config/03-multi-pass.yaml']);17 expect(getExpectedOutput('03-multi-pass')).toStrictEqual(getProducedOutput());18});19test('04 controller import test', async () => {20 await execute(['-c', 'config/04-controller-test.yaml']);21 expect(getExpectedOutput('04-controller-test')).toStrictEqual(getProducedOutput());22});23test('05 controller can access config', async () => {24 await execute(['-c', 'config/05-controller-context.yaml']);25 expect(getExpectedOutput('05-controller-context')).toStrictEqual(getProducedOutput());26});27test('06 controller import cli() when exists', async () => {28 await execute(['-c', 'config/06-controller-cli.yaml']);29 expect(getExpectedOutput('06-controller-cli')).toStrictEqual(getProducedOutput());30});31test('07 controller import default() when exists', async () => {32 await execute(['-c', 'config/07-controller-default.yaml']);33 expect(getExpectedOutput('07-controller-default')).toStrictEqual(getProducedOutput());34});35test('17 controller import myCustomController() when exists', async () => {36 await execute(['-c', 'config/17-controller-custom.yaml']);37 expect(getExpectedOutput('17-controller-custom')).toStrictEqual(getProducedOutput());...
diffs.spec.js
Source:diffs.spec.js
...14describe('diffs', function () {15 var diffs, expected;16 before(function (done) {17 run('diffs/diffs.fixture.js', ['-C'], function (err, res) {18 expected = getExpectedOutput();19 diffs = getDiffs(res.output.replace(/\r\n/g, '\n'));20 done(err);21 });22 });23 [24 'should display a diff for small strings',25 'should display a diff of canonicalized objects',26 'should display a diff for medium strings',27 'should display a diff for entire object dumps',28 'should display a diff for multi-line strings',29 'should display a diff for entire object dumps',30 'should display a full-comparison with escaped special characters',31 'should display a word diff for large strings',32 'should work with objects',...
diffs.js
Source:diffs.js
2var helpers = require('./helpers');3var run = helpers.runMocha;4var fs = require('fs');5var getDiffs = helpers.getDiffs;6function getExpectedOutput() {7 var output = fs.readFileSync('test/integration/fixtures/diffs/output', 'UTF8');8 // Diffs are delimited in file by "// DIFF"9 return output.split(/\s*\/\/ DIFF/).slice(1).map(function(diff) {10 return diff.split('\n').filter(Boolean).join('\n');11 });12}13describe('diffs', function() {14 var diffs, expected;15 this.timeout(1000);16 before(function(done) {17 run('diffs/diffs.js', ['-C'], function(err, res) {18 expected = getExpectedOutput();19 diffs = getDiffs(res.output);20 done(err);21 });22 });23 [24 'should display a diff for small strings',25 'should display a diff of canonicalized objects',26 'should display a diff for medium strings',27 'should display a diff for entire object dumps',28 'should display a diff for multi-line strings',29 'should display a diff for entire object dumps',30 'should display a full-comparison with escaped special characters',31 'should display a word diff for large strings',32 'should work with objects',...
cliparams.test.js
Source:cliparams.test.js
...5 rimraf.sync(__dirname + '/temp');6});7test('14 simple passtrough from console input', async () => {8 await execute(['-f', './lib/reader-all', '-t', './lib/writer']);9 expect(getExpectedOutput('14-simple-pass-cli')).toStrictEqual(getProducedOutput());10});11test('15 controller from cli input', async () => {12 await execute(['-f', './lib/reader-all', '-t', './lib/writer', '-s', './lib/controller-prop']);13 expect(getExpectedOutput('15-controller-test-cli')).toStrictEqual(getProducedOutput());14});15test('16 controller context value acces from cli input', async () => {16 await execute(['-f', './lib/reader-all', '-t', './lib/writer', '-s', './lib/controller-context', '-v', '{"configValue":"foo bar"}']);17 expect(getExpectedOutput('16-controller-context-cli')).toStrictEqual(getProducedOutput());...
ResultsCounter.spec.js
Source:ResultsCounter.spec.js
...5const getExpectedOutput = (counter) => `About ${counter} results`;6describe('<ResultsCounter />', () => {7 test('renders formatted number', () => {8 const tree = factory({ counter: 10000 });9 expect(tree.text()).toBe(getExpectedOutput('10,000'));10 });...
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!!