How to use mockery - 10 common examples

To help you get started, we’ve selected a few mockery 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 cksource / mrgit / tests / commands / status.js View on Github external
packageName: '@ckeditor/ckeditor5-test-package',
			arguments: []
		};

		// Do not modify the color.
		mockery.registerMock( 'chalk', {
			cyan: stubs.chalk.cyan.callsFake( msg => msg ),
			bold: stubs.chalk.bold.callsFake( msg => msg ),
			yellow: stubs.chalk.yellow.callsFake( msg => msg ),
			green: stubs.chalk.green.callsFake( msg => msg ),
			red: stubs.chalk.red.callsFake( msg => msg ),
			blue: stubs.chalk.blue.callsFake( msg => msg ),
			magenta: stubs.chalk.magenta.callsFake( msg => msg ),
			underline: stubs.chalk.magenta.callsFake( msg => msg )
		} );
		mockery.registerMock( 'cli-table', class Table {
			constructor( ...args ) {
				stubs.table.constructor( ...args );
			}

			push( ...args ) {
				return stubs.table.push( ...args );
			}

			toString( ...args ) {
				return stubs.table.toString( ...args );
			}
		} );
		mockery.registerMock( './exec', stubs.execCommand );
		mockery.registerMock( '../utils/gitstatusparser', stubs.gitStatusParser );

		statusCommand = require( '../../lib/commands/status' );
github IBM-Cloud / phonebot / test / unit / phonebot.js View on Github external
before(function() {
    mockery.enable(); // Enable mockery at the start of your test suite
    mockery.warnOnUnregistered(false);
    mockery.registerMock('./translate.js', translate);
    mockery.registerMock('request', {
      post: function () {}
    })
    PhoneBot = require('../../lib/phonebot.js')
  })
github robtweed / ewd-qoper8 / spec / unit / worker / proto / init.spec.js View on Github external
it('should init worker process message handler', function () {
        // ARRANGE
        var workerModule = jasmine.createSpyObj(['bar']);
        mockery.registerMock('foo', workerModule);

        process.argv = ['node', 'test.js', 'foo.bar'];

        // ACT
        workerProcess.init();

        // ASSERT
        expect(workerModule.bar).toHaveBeenCalledWithContext(workerProcess);
      });
    });
github robtweed / ewd-qoper8 / spec / unit / worker / proto / init.spec.js View on Github external
it('should init worker process message handler', function () {
        // ARRANGE
        var workerModule = jasmine.createSpy();
        mockery.registerMock('foo', workerModule);

        process.argv = ['node', 'test.js', 'foo'];

        // ACT
        workerProcess.init();

        // ASSERT
        expect(workerModule).toHaveBeenCalledWithContext(workerProcess);
      });
    });
github felixrieseberg / windows-build-tools / test / src / install.js View on Github external
it('should attempt to download the build tools', (done) => {
      const nuggetMock = function (url, options, cb) {
        url.should.equal(constants.buildToolsUrl)
        options.should.be.ok
        options.target.should.be.ok
        options.dir.should.be.ok

        cb()
      }

      mockery.registerMock('nugget', nuggetMock)
      require('../../lib/download')().should.be.fulfilled.and.notify(done)
      mockery.deregisterMock('nugget')
    })
  })
github Financial-Times / polyfill-library / test / unit / lib / UA.js View on Github external
beforeEach(() => {
		useragent = require('useragent');
		UA = require('../../../lib/UA');
		lruCache = require('../mock/lru-cache.mock');
		mockery.registerMock('lru-cache', lruCache);
	});
github Financial-Times / polyfill-service / test / unit / lib / UA.js View on Github external
beforeEach(() => {
		useragent = require('useragent');
		UA = require('../../../lib/UA');
		lruCache = require('../mock/lru-cache.mock');
		mockery.registerMock('lru-cache', lruCache);
	});
github johnpapa / lite-server / test / config-defaults.spec.js View on Github external
beforeEach(() => {
    mockery.enable({ useCleanCache: true });

    fallbackMock = sinon.stub();
    mockery.registerMock('connect-history-api-fallback', fallbackMock);

    loggerMock = sinon.stub();
    mockery.registerMock('connect-logger', loggerMock);

    mockery.registerAllowable('../lib/config-defaults');
  });
github springernature / shunter / tests / server / core / config.js View on Github external
beforeEach(function () {
			env = process.env.NODE_ENV;
			process.env.NODE_ENV = 'ci';

			mockery.enable({
				useCleanCache: true,
				warnOnUnregistered: false,
				warnOnReplace: false
			});
			mockery.registerMock('os', require('../mocks/os'));
			mockedLoggingLib = require('../mocks/logging');
			mockery.registerMock('./logging', mockedLoggingLib);
		});
github rowanmanning / joblint / test / unit / linter.js View on Github external
beforeEach(function () {
        mockery.enable({
            useCleanCache: true,
            warnOnUnregistered: false,
            warnOnReplace: false
        });

        createResult = require('../mock/result');
        mockery.registerMock('./result', createResult);

        createSpec = require('../mock/spec');
        mockery.registerMock('./spec', createSpec);

        createLinter = require('../../lib/linter');
    });

mockery

Simplifying the use of mocks with Node.js

Unrecognized
Latest version published 7 years ago

Package Health Score

35 / 100
Full package analysis