How to use mock-require - 10 common examples

To help you get started, we’ve selected a few mock-require 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 blackbaud / skyux-builder / test / cli-utils-run-build.spec.js View on Github external
{
        encoding: 'utf8'
      }
    );

    // Ensure the TypeScript config file is written to disk.
    expect(writeJSONSpy).toHaveBeenCalledWith(
      skyPagesConfigUtil.spaPathTempSrc('tsconfig.json'),
      jasmine.objectContaining({
        'files': [
          './app/app.module.ts'
        ]
      })
    );

    mock.stop(f);
  });
github OldSneerJaw / synctos / src / testing / test-environment-maker.spec.js View on Github external
beforeEach(() => {
    // Mock out the "require" calls in the module under test
    fsMock = { readFileSync: simpleMock.stub() };
    mockRequire('fs', fsMock);

    vmMock = { runInThisContext: simpleMock.stub() };
    mockRequire('vm', vmMock);

    testEnvironmentMaker = mockRequire.reRequire('./test-environment-maker');
  });
github OldSneerJaw / synctos / src / loading / file-fragment-loader.spec.js View on Github external
beforeEach(function() {
    // Mock out the "require" calls in the module under test
    fsMock = { readFileSync: simpleMock.stub() };
    mockRequire('fs', fsMock);
    fileFragmentLoader = mockRequire.reRequire('./file-fragment-loader.js');
  });
github blackbaud / skyux-builder / test / config-webpack-build-public-library.spec.js View on Github external
it('should expose a getWebpackConfig method', () => {
    const lib = mock.reRequire(configPath);
    expect(typeof lib.getWebpackConfig).toEqual('function');
  });
github blackbaud / skyux-builder / test / config-webpack-build-public-library.spec.js View on Github external
it('should return a config object', () => {
    const lib = mock.reRequire(configPath);
    const config = lib.getWebpackConfig(skyPagesConfig);
    expect(config).toEqual(jasmine.any(Object));
  });
github blackbaud / skyux-builder / test / index.spec.js View on Github external
it('should expose a runCommand method', () => {
    const lib = mock.reRequire('../index');
    expect(typeof lib.runCommand).toEqual('function');
  });
github academia-de-codigo / noire-server / test / config / index.js View on Github external
it('requires common config file', () => {
        //setup
        process.env.NODE_ENV = 'dev';

        //exercise
        config = Mock.reRequire('config');

        //verify
        expect(config).to.be.an.object();
        expect(config.common).to.be.a.boolean();
        expect(config.common).to.equals(true);
    });
github kirjs / react-highcharts / test / unit / nonbundleSpec.js View on Github external
beforeEach(()=>{
      fakeHighcharts = {};
        console.log(modulename);
      mock(modulename, fakeHighcharts);
      Component = mock.reRequire('../../' + libPath);
    });
github xuexb / github-bot / test / utils.js View on Github external
/**
 * @file utils.js test case
 * @author xuexb 
 */
require('mock-require').stopAll()
const utils = require('../src/utils')
const expect = require('chai').expect

describe('utils.js', () => {
  describe('.toArray', () => {
    it('should return self if empty', () => {
      expect(utils.toArray()).to.be.undefined
      expect(utils.toArray('')).to.equal('')
      expect(utils.toArray(null)).to.be.null
    })
    it('should return array if not the empty string', () => {
      expect(utils.toArray(['string'])).to.be.a('array').and.to.deep.equal(['string'])
      expect(utils.toArray('string')).to.be.a('array').and.to.deep.equal(['string'])
    })
  })
github SAP / ui5-project / test / lib / translators / npm.js View on Github external
return npmTranslator.generateDependencyTree(applicationAPath).then((parsedTree) => {
		t.deepEqual(parsedTree, applicationATree, "Parsed correctly");
		mock.stop("@ui5/logger");
	});
});

mock-require

Simple, intuitive mocking of Node.js modules.

MIT
Latest version published 6 years ago

Package Health Score

56 / 100
Full package analysis