How to use the jest-mock.ModuleMocker function in jest-mock

To help you get started, we’ve selected a few jest-mock 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 thymikee / jest-preset-angular / testEnvironment.js View on Github external
constructor(config) {
    // lazy require
    const {JSDOM} = require('jsdom');
    
    this.document = new JSDOM('', {
      url: config.testURL,
      runScripts: 'dangerously'
    });
    const global = (this.global = this.document.window.document.defaultView);
    // Node's error-message stack size is limited at 10, but it's pretty useful
    // to see more than that when a test fails.
    global.Error.stackTraceLimit = 100;
    installCommonGlobals(global, config.globals);

    this.moduleMocker = new mock.ModuleMocker(global);
    this.fakeTimers = new FakeTimers(global, this.moduleMocker, config);
  }
github NikhilVerma / jest-environment-node-debug-fixed / index.js View on Github external
constructor(config) {

        // jest doesn't need full global before runScript, but to reduce possible issues we create full copy here
        this.global = assign({}, global, deepCopy(config.globals));

        this.moduleMocker = new ModuleMocker(global);
        this.fakeTimers = new FakeTimers(this.global, this.moduleMocker, config);
    }
github sourcegraph / sourcegraph / shared / dev / jest-environment.js View on Github external
const originalAddListener = global.addEventListener
    const originalRemoveListener = global.removeEventListener
    global.addEventListener = function(...args) {
      if (args[0] === 'error') {
        userErrorListenerCount++
      }
      return originalAddListener.apply(this, args)
    }
    global.removeEventListener = function(...args) {
      if (args[0] === 'error') {
        userErrorListenerCount--
      }
      return originalRemoveListener.apply(this, args)
    }
    /* eslint-enable @typescript-eslint/unbound-method */
    this.moduleMocker = new ModuleMocker(global)
    const timerConfig = {
      idToRef: id => id,
      refToId: ref => ref,
    }
    this.fakeTimers = new JestFakeTimers({
      config,
      global,
      moduleMocker: this.moduleMocker,
      timerConfig,
    })
    this.global.jsdom = this.dom
  }
  setup() {
github d4rkr00t / jest-electron-runner / packages / jest-environment-electron / index.js View on Github external
constructor(config) {
    const global = (this.global = window);
    installCommonGlobals(global, config.globals);
    this.moduleMocker = new mock.ModuleMocker(global);
    this.fakeTimers = new FakeTimers(global, this.moduleMocker, config);
  }
github facebook-atom / jest-electron-runner / packages / electron / src / Environment.js View on Github external
constructor(config: ProjectConfig) {
    this.global = global;
    this.moduleMocker = new mock.ModuleMocker(global);
    this.fakeTimers = {
      useFakeTimers() {
        throw new Error('fakeTimers are not supproted in electron environment');
      },
      clearAllTimers() {},
    };
    installCommonGlobals(global, config.globals);
  }
github facebookarchive / atom-ide-ui / modules / jest-atom-runner / src / environment.js View on Github external
constructor(config: ProjectConfig) {
    this.global = global;
    this.moduleMocker = new mock.ModuleMocker(global);
    this.fakeTimers = {
      useFakeTimers() {
        throw new Error('fakeTimers are not supproted in atom environment');
      },
    };
  }
github ringcentral / ringcentral-js-widgets / packages / ringcentral-e2e-environment / src / index.js View on Github external
let userErrorListenerCount = 0;
      global.addEventListener = function (name) {
        if (name === 'error') {
          userErrorListenerCount++;
        }
        return originalAddListener.apply(this, arguments);
      };
      global.removeEventListener = function (name) {
        if (name === 'error') {
          userErrorListenerCount--;
        }
        return originalRemoveListener.apply(this, arguments);
      };
    }  

    this.moduleMocker = new mock.ModuleMocker(global);

    const timerConfig = {
      idToRef: id => id,
      refToId: ref => ref,
    };

    this.fakeTimers = new FakeTimers({
      config: this._config,
      global,
      moduleMocker: this.moduleMocker,
      timerConfig,
    });
  }
github unadlib / tees / packages / tees-environment / src / index.js View on Github external
let userErrorListenerCount = 0;
      global.addEventListener = function (name) {
        if (name === 'error') {
          userErrorListenerCount++;
        }
        return originalAddListener.apply(this, arguments);
      };
      global.removeEventListener = function (name) {
        if (name === 'error') {
          userErrorListenerCount--;
        }
        return originalRemoveListener.apply(this, arguments);
      };
    }  

    this.moduleMocker = new mock.ModuleMocker(global);

    const timerConfig = {
      idToRef: id => id,
      refToId: ref => ref,
    };

    this.fakeTimers = new FakeTimers({
      config: this._config,
      global,
      moduleMocker: this.moduleMocker,
      timerConfig,
    });
  }
github facebookarchive / atom-ide-ui / modules / nuclide-jest / AtomJestEnvironment.js View on Github external
constructor(config) {
    const global = (this.global = window);
    installCommonGlobals(global, config.globals);
    this.moduleMocker = new mock.ModuleMocker(global);
    this.fakeTimers = new FakeTimers({
      config,
      global,
      moduleMocker: this.moduleMocker,
    });
  }

jest-mock

**Note:** More details on user side API can be found in [Jest documentation](https://jestjs.io/docs/mock-function-api).

MIT
Latest version published 1 year ago

Package Health Score

88 / 100
Full package analysis