How to use jest-util - 10 common examples

To help you get started, we’ve selected a few jest-util 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 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 mozilla / addons-frontend / tests / jest-reporters / fingers-crossed.js View on Github external
printTestFileHeader(testPath, config, result) {
    this.log(getResultHeader(result, this._globalConfig, config));

    const consoleBuffer = result.console;
    const testFailed = result.numFailingTests > 0;

    if (testFailed && consoleBuffer && consoleBuffer.length) {
      // prettier-ignore
      this.log(
        `  ${TITLE_BULLET}Console\n\n${getConsoleOutput(
          config.cwd,
          !!this._globalConfig.verbose,
          consoleBuffer
        )}`
      );
    }
  }
}
github facebook / jest / packages / jest-circus / src / index.ts View on Github external
asyncError.message = `Invalid second argument, ${blockFn}. It must be a callback function.`;
    throw asyncError;
  }
  dispatch({
    asyncError,
    blockName,
    mode,
    name: 'start_describe_definition',
  });
  const describeReturn = blockFn();

  // TODO throw in Jest 25
  if (isPromise(describeReturn)) {
    console.log(
      formatExecError(
        new ErrorWithStack(
          chalk.yellow(
            'Returning a Promise from "describe" is not supported. Tests must be defined synchronously.\n' +
              'Returning a value from "describe" will fail the test in a future version of Jest.',
          ),
          describeFn,
        ),
        {rootDir: '', testMatch: []},
        {noStackTrace: false},
      ),
    );
  } else if (describeReturn !== undefined) {
    console.log(
      formatExecError(
        new ErrorWithStack(
          chalk.yellow(
            'A "describe" callback must not return a value.\n' +
github sourcegraph / sourcegraph / shared / dev / jest-environment.js View on Github external
constructor(config, options = {}) {
    this.dom = new JSDOM('', {
      pretendToBeVisual: true,
      runScripts: 'dangerously',
      url: config.testURL,
      virtualConsole: new VirtualConsole().sendTo(options.console || console),
      ...config.testEnvironmentOptions,
    })
    const global = (this.global = this.dom.window.document.defaultView)
    if (!global) {
      throw new Error('JSDOM did not return a Window object')
    }
    // Node's error-message stack size is limited at 10, but it's pretty useful
    // to see more than that when a test fails.
    this.global.Error.stackTraceLimit = 100
    installCommonGlobals(global, config.globals)
    // Report uncaught errors.
    let userErrorListenerCount = 0
    this.errorEventListener = event => {
      if (userErrorListenerCount === 0 && event.error) {
        process.emit('uncaughtException', event.error)
      }
    }
    global.addEventListener('error', this.errorEventListener)
    // However, don't report them as uncaught if the user listens to 'error' event.
    // In that case, we assume the might have custom error handling logic.
    /* eslint-disable @typescript-eslint/unbound-method */
    const originalAddListener = global.addEventListener
    const originalRemoveListener = global.removeEventListener
    global.addEventListener = function(...args) {
      if (args[0] === 'error') {
        userErrorListenerCount++
github Marwan01 / food-converter / node_modules / jest-jasmine2 / build / index.js View on Github external
environment.global.xit = (...args) => {
        const stack = (0, _jestUtil.getCallsite)(1, runtime.getSourceMaps());
        const xit = originalXit(...args); // @ts-ignore

        xit.result.__callsite = stack;
        return xit;
      };
github makuga01 / dnsFookup / FE / node_modules / jest-jasmine2 / build / index.js View on Github external
environment.global.fit = (...args) => {
        const stack = (0, _jestUtil.getCallsite)(1, runtime.getSourceMaps());
        const fit = originalFit(...args); // @ts-ignore

        fit.result.__callsite = stack;
        return fit;
      };
    }
github flaviuse / mern-authentication / client / node_modules / jest-jasmine2 / build / index.js View on Github external
environment.global.xit = (...args) => {
        const stack = (0, _jestUtil.getCallsite)(1, runtime.getSourceMaps());
        const xit = originalXit(...args); // @ts-ignore

        xit.result.__callsite = stack;
        return xit;
      };
github facebook / jest / packages / jest-circus / src / index.ts View on Github external
throw asyncError;
  }
  if (typeof blockFn !== 'function') {
    asyncError.message = `Invalid second argument, ${blockFn}. It must be a callback function.`;
    throw asyncError;
  }
  dispatch({
    asyncError,
    blockName,
    mode,
    name: 'start_describe_definition',
  });
  const describeReturn = blockFn();

  // TODO throw in Jest 25
  if (isPromise(describeReturn)) {
    console.log(
      formatExecError(
        new ErrorWithStack(
          chalk.yellow(
            'Returning a Promise from "describe" is not supported. Tests must be defined synchronously.\n' +
              'Returning a value from "describe" will fail the test in a future version of Jest.',
          ),
          describeFn,
        ),
        {rootDir: '', testMatch: []},
        {noStackTrace: false},
      ),
    );
  } else if (describeReturn !== undefined) {
    console.log(
      formatExecError(
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);
    }