How to use the jest-util.ErrorWithStack function in jest-util

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 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 gitlabhq / gitlabhq / spec / frontend / environment.js View on Github external
warn(...args) {
        throw new ErrorWithStack(
          `Unexpected call of console.warn() with:\n\n${args.join(', ')}`,
          this.warn,
        );
      },
    });
github flaviuse / mern-authentication / client / node_modules / jest-jasmine2 / build / jasmine / Env.js View on Github external
this.todo = function() {
          const description = arguments[0];

          if (arguments.length !== 1 || typeof description !== 'string') {
            throw new _jestUtil.ErrorWithStack(
              'Todo must be called with only a description.',
              test.todo
            );
          }

          const spec = specFactory(
            description,
            () => {},
            currentDeclarationSuite
          );
          spec.todo();
          currentDeclarationSuite.addChild(spec);
          return spec;
        };
github facebook / jest / packages / jest-circus / src / index.ts View on Github external
const _dispatchDescribe = (
  blockFn: Circus.BlockFn,
  blockName: Circus.BlockName,
  describeFn: DescribeFn,
  mode?: Circus.BlockMode,
) => {
  const asyncError = new ErrorWithStack(undefined, describeFn);
  if (blockFn === undefined) {
    asyncError.message = `Missing second argument. It must be a callback function.`;
    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();
github gitlabhq / gitlabhq / spec / frontend / helpers / fixtures.js View on Github external
export function getFixture(relativePath) {
  const absolutePath = path.join(global.fixturesBasePath, relativePath);
  if (!fs.existsSync(absolutePath)) {
    throw new ErrorWithStack(
      `Fixture file ${relativePath} does not exist.

Did you run bin/rake karma:fixtures?`,
      getFixture,
    );
  }

  return fs.readFileSync(absolutePath, 'utf8');
}
github facebook / jest / packages / jest-circus / src / index.ts View on Github external
const _addTest = (
    testName: Circus.TestName,
    mode: Circus.TestMode,
    fn: Circus.TestFn | undefined,
    testFn: (
      testName: Circus.TestName,
      fn: Circus.TestFn,
      timeout?: number,
    ) => void,
    timeout?: number,
  ) => {
    const asyncError = new ErrorWithStack(undefined, testFn);

    if (typeof testName !== 'string') {
      asyncError.message = `Invalid first argument, ${testName}. It must be a string.`;

      throw asyncError;
    }
    if (fn === undefined) {
      asyncError.message =
        'Missing second argument. It must be a callback function. Perhaps you want to use `test.todo` for a test placeholder.';

      throw asyncError;
    }
    if (typeof fn !== 'function') {
      asyncError.message = `Invalid second argument, ${fn}. It must be a callback function.`;

      throw asyncError;
github Marwan01 / food-converter / node_modules / jest-jasmine2 / build / jasmine / Env.js View on Github external
this.todo = function() {
          const description = arguments[0];

          if (arguments.length !== 1 || typeof description !== 'string') {
            throw new _jestUtil.ErrorWithStack(
              'Todo must be called with only a description.',
              test.todo
            );
          }

          const spec = specFactory(
            description,
            () => {},
            currentDeclarationSuite
          );
          spec.todo();
          currentDeclarationSuite.addChild(spec);
          return spec;
        };