How to use mocha - 10 common examples

To help you get started, we’ve selected a few mocha examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googleapis / nodejs-redis / test / gapic-cloud_redis-v1.ts View on Github external
client
        .exportInstance(request)
        .then((responses: [Operation]) => {
          const operation = responses[0];
          return operation ? operation.promise() : {};
        })
        .then((responses: [Operation]) => {
          assert.deepStrictEqual(responses[0], expectedResponse);
          done();
        })
        .catch((err: {}) => {
          done(err);
        });
    });

    it('invokes exportInstance with error', done => {
      const client = new cloudredisModule.v1.CloudRedisClient({
        credentials: {client_email: 'bogus', private_key: 'bogus'},
        projectId: 'bogus',
      });
      // Mock request
      const request: protosTypes.google.cloud.redis.v1.IExportInstanceRequest = {};
      // Mock response
      const expectedResponse = {};
      // Mock gRPC layer
      client._innerApiCalls.exportInstance = mockLongRunningGrpcMethod(
        request,
        null,
        error
      );
      client
        .exportInstance(request)
github garriguv / soundcloudql / src / schema / __tests__ / track.js View on Github external
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { soundcloud } from './soundcloudql';

/* eslint-disable max-len */

describe('Track type', function () {
  it('Gets an object by id', function () {
    var query = '{ track(id: 2) { title }}';
    return soundcloud(query).then(function (result) {
      expect(result.data.track.title).to.equal('Electro 1');
    });
  });

  it('Gets all properties', function () {
    var query = `
{
  track(id: 2) {
    id
    title
    createdAt
    description
    commentCount
github zhilu-nanjing / financial-cell / test / core / errorPop_test_scsslint_tmp5591952202215759686.js View on Github external
it('  1.23.23  ', function () {
            let formatProxy = new FormatProxy();
            let _cell = formatProxy.makeFormatCell({text: "1.23.23", formula: "1.23.23"}, {
                symbol: "%",
                position: "end"
            }, (s) => {
                return calcDecimals(s, (s2) => {
                    return s2 * 100;
                });
            });
            assert.equal(_cell, null);
        });
    });

    describe('  special_formula_process  ', () => {
        it('  *HYPERLINK*/*MULTIPLECELLS*  ', function () {
            // let args = specialWebsiteValue('*HYPERLINK*!{"text":"www.baidu.com","url":"www.baidu.com"} ', "=ADD()");
            // assert.equal(args.state, true);
            // assert.equal(args.text, "www.baidu.com");
            // assert.equal(args.type, 2);
            //
            // let wb = {
            //     "A1": {
            //         "v": "1",
            //         "f": "1"
            //     },
            //     "B1": {
            //         "v": "2",
            //         "f": "2"
            //     }
            // }
github luckymarmot / API-Flow / testing / mocha-runner.js View on Github external
function runSuite() {
  Object.keys(require.cache).forEach(key => delete require.cache[key])
  const mocha = new Mocha({ reporter: 'spec' })
  fileList.forEach(filepath => mocha.addFile(filepath))
  try {
    mocha.run()
    if (global.gc) {
      global.gc()
    }
    else {
      /* eslint-disable no-console */
      console.log('Garbage collection unavailable')
      /* eslint-enable no-console */
    }
  }
  catch (e) {
    /* eslint-disable no-console */
    console.log('------------')
    console.log('Failed with Error', e.stack)
github mocha-parallel / mocha-parallel-tests / src / subprocess / runner.ts View on Github external
export function runMocha(file: string, options: ThreadOptions, debugSubprocess: boolean) {
  const channel = new MessageChannel();
  const Reporter = getReporterFactory(channel, debugSubprocess);

  const mocha = new Mocha();
  mocha.addFile(file);

  // --compilers
  applyCompilers(options.compilers);

  // --delay
  applyDelay(mocha, options.delay);

  // --grep
  applyGrepPattern(mocha, options.grep);

  // --enableTimeouts
  applyNoTimeouts(mocha, options.enableTimeouts);

  // --exit
  const onComplete = applyExit(channel, options.exitImmediately);
github oliviertassinari / react-event-listener / test / unit.js View on Github external
jsdom,
} from 'jsdom';

global.document = jsdom('');
global.window = document.defaultView;
global.navigator = global.window.navigator;
global.Node = global.window.Node;

const argv = minimist(process.argv.slice(2), {
  alias: {
    c: 'component',
    g: 'grep',
  },
});

const mocha = new Mocha({
  grep: argv.grep ? argv.grep : undefined,
});

glob(`src/**/${argv.component ? argv.component : '*'}.spec.js`, {}, (err, files) => {
  files.forEach((file) => mocha.addFile(file));

  mocha.run((failures) => {
    process.on('exit', () => {
      /* eslint-disable no-process-exit */
      process.exit(failures);
    });
  });
});
github oliviertassinari / babel-plugin-react-remove-properties / test / index.js View on Github external
import minimist from 'minimist';
import Mocha from 'mocha';
import glob from 'glob';

const argv = minimist(process.argv.slice(2), {
  alias: {
    m: 'module',
    g: 'grep',
  },
});

const globPatterns = [
  `test/**/${argv.module ? argv.module : '*'}.spec.js`,
];

const mocha = new Mocha({
  grep: argv.grep ? argv.grep : undefined,
});

glob(
  globPatterns.length > 1 ? `{${globPatterns.join(',')}}` : globPatterns[0],
  {},
  (err, files) => {
    files.forEach((file) => mocha.addFile(file));
    mocha.run((failures) => {
      process.on('exit', () => {
        process.exit(failures); // eslint-disable-line no-process-exit
      });
    });
  }
);
github oliviertassinari / react-swipeable-views / test / unit.js View on Github external
global[property] = document.defaultView[property];
  }
});

global.navigator = {
  userAgent: 'node.js',
};

const argv = minimist(process.argv.slice(2), {
  alias: {
    c: 'component',
    g: 'grep',
  },
});

const mocha = new Mocha({
  grep: argv.grep ? argv.grep : undefined,
  reporter: 'dot',
});

glob(`packages/**/src/**/${argv.component ? argv.component : '*'}.spec.js`, {}, (err, files) => {
  files.forEach((file) => mocha.addFile(file));

  mocha.run((failures) => {
    process.on('exit', () => {
      process.exit(failures); // eslint-disable-line no-process-exit
    });
  });
});
github Silk-GUI / Silk / test / watch_data.spec.js View on Github external
describe('get and set', function () {
    it('should be able to set and get a property', function () {
      var value;

      data.set('testProperty', 'testValue');
      value = data.get('testProperty');
      expect(value).to.equal('testValue');
    });
    it('should replace value if property exists', function () {
      var value;

      // set initial value
      data.set('testProperty', 'testValue');
      // replace value
      data.set('testProperty', 'newValue');
      value = data.get('testProperty');
      expect(value).to.equal('newValue');
    });
github clusterio / factorioClusterio / test / master.js View on Github external
describe('Master testing', function() {
	describe('#GET /api/getFactorioLocale', function() {
		it('should get the basegame factorio locale', async function() {
			let res = await get('/api/getFactorioLocale');
			let object = res.body;

			// test that it is looks like a factorio locale
			assert.equal(typeof object, "object");
			assert.equal(object["entity-name"]["fish"], "Fish");
			assert.equal(object["entity-name"]["small-lamp"], "Lamp");
		});
	});
	// describe("#GET /api/")
	parallel("#GET static website data", function() {
		this.timeout(6000);

		let paths = ["/", "/nodes", "/settings", "/nodeDetails"];
		for (let path of paths) {
			it(`sends some HTML when accessing ${path}`, () => getValidate(path));
		}
	});

	describe("class SocketIOServerConnector", function() {
		let testConnector = new master._SocketIOServerConnector(new mock.MockSocket());
		describe(".disconnect()", function() {
			it("should call disconnect on the socket", function() {
				testConnector._socket.disconnectCalled = false;
				testConnector.disconnect();
				assert(testConnector._socket.disconnectCalled, "Disconnect was not called");
			});