How to use the warning.mock function in warning

To help you get started, we’ve selected a few warning 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 / relay / packages / relay-test-utils-internal / Matchers.js View on Github external
}

  function formatActual(calls) {
    if (calls.length) {
      return calls
        .map(args => {
          return formatArray([!!args[0]].concat(args.slice(1)));
        })
        .join(', ');
    } else {
      return '[]';
    }
  }

  const warning = require('warning');
  if (!warning.mock) {
    throw new Error("toWarn(): Requires `jest.mock('warning')`.");
  }

  const callsCount = warning.mock.calls.length;
  actual();
  const calls = warning.mock.calls.slice(callsCount);

  // Simple case: no explicit expectation.
  if (!expected) {
    const warned = calls.filter(args => !args[0]).length;
    return {
      pass: !!warned,
      message: () =>
        `Expected ${negative ? 'not ' : ''}to warn but ` +
        '`warning` received the following calls: ' +
        `${formatActual(calls)}.`,
github facebook / relay / packages / relay-test-utils / RelayModernTestUtils.js View on Github external
return calls
          .map(args => {
            return formatArray([!!args[0]].concat(args.slice(1)));
          })
          .join(', ');
      } else {
        return '[]';
      }
    }

    const warning = require('warning');
    if (!warning.mock) {
      throw new Error("toWarn(): Requires `jest.mock('warning')`.");
    }

    const callsCount = warning.mock.calls.length;
    actual();
    const calls = warning.mock.calls.slice(callsCount);

    // Simple case: no explicit expectation.
    if (!expected) {
      const warned = calls.filter(args => !args[0]).length;
      return {
        pass: !!warned,
        message: () =>
          `Expected ${negative ? 'not ' : ''}to warn but ` +
          '`warning` received the following calls: ' +
          `${formatActual(calls)}.`,
      };
    }

    // Custom case: explicit expectation.
github facebook / relay / packages / relay-test-utils / RelayModernTestUtils.js View on Github external
}

      function formatActual(calls) {
        if (calls.length) {
          return calls
            .map(args => {
              return formatArray([!!args[0]].concat(args.slice(1)));
            })
            .join(', ');
        } else {
          return '[]';
        }
      }

      const warning = require('warning');
      if (!warning.mock) {
        throw new Error("toWarn(): Requires `jest.mock('warning')`.");
      }

      const callsCount = warning.mock.calls.length;
      actual();
      const calls = warning.mock.calls.slice(callsCount);

      // Simple case: no explicit expectation.
      if (!expected) {
        const warned = calls.filter(args => !args[0]).length;
        return {
          pass: !!warned,
          message: () =>
            `Expected ${negative ? 'not ' : ''}to warn but ` +
            '`warning` received the following calls: ' +
            `${formatActual(calls)}.`,
github facebook / relay / packages / relay-test-utils / RelayModernTestUtils.js View on Github external
}

    function formatActual(calls) {
      if (calls.length) {
        return calls
          .map(args => {
            return formatArray([!!args[0]].concat(args.slice(1)));
          })
          .join(', ');
      } else {
        return '[]';
      }
    }

    const warning = require('warning');
    if (!warning.mock) {
      throw new Error("toWarn(): Requires `jest.mock('warning')`.");
    }

    const callsCount = warning.mock.calls.length;
    actual();
    const calls = warning.mock.calls.slice(callsCount);

    // Simple case: no explicit expectation.
    if (!expected) {
      const warned = calls.filter(args => !args[0]).length;
      return {
        pass: !!warned,
        message: () =>
          `Expected ${negative ? 'not ' : ''}to warn but ` +
          '`warning` received the following calls: ' +
          `${formatActual(calls)}.`,
github facebook / relay / packages / relay-test-utils / RelayModernTestUtils.js View on Github external
return formatArray([!!args[0]].concat(args.slice(1)));
            })
            .join(', ');
        } else {
          return '[]';
        }
      }

      const warning = require('warning');
      if (!warning.mock) {
        throw new Error("toWarn(): Requires `jest.mock('warning')`.");
      }

      const callsCount = warning.mock.calls.length;
      actual();
      const calls = warning.mock.calls.slice(callsCount);

      // Simple case: no explicit expectation.
      if (!expected) {
        const warned = calls.filter(args => !args[0]).length;
        return {
          pass: !!warned,
          message: () =>
            `Expected ${negative ? 'not ' : ''}to warn but ` +
            '`warning` received the following calls: ' +
            `${formatActual(calls)}.`,
        };
      }

      // Custom case: explicit expectation.
      if (!Array.isArray(expected)) {
        expected = [expected];
github facebook / relay / packages / relay-test-utils-internal / Matchers.js View on Github external
return formatArray([!!args[0]].concat(args.slice(1)));
        })
        .join(', ');
    } else {
      return '[]';
    }
  }

  const warning = require('warning');
  if (!warning.mock) {
    throw new Error("toWarn(): Requires `jest.mock('warning')`.");
  }

  const callsCount = warning.mock.calls.length;
  actual();
  const calls = warning.mock.calls.slice(callsCount);

  // Simple case: no explicit expectation.
  if (!expected) {
    const warned = calls.filter(args => !args[0]).length;
    return {
      pass: !!warned,
      message: () =>
        `Expected ${negative ? 'not ' : ''}to warn but ` +
        '`warning` received the following calls: ' +
        `${formatActual(calls)}.`,
    };
  }

  // Custom case: explicit expectation.
  if (!Array.isArray(expected)) {
    expected = [expected];
github facebook / relay / packages / react-relay / classic / tools / __mocks__ / RelayTestUtils.js View on Github external
return formatArray([!!args[0]].concat(args.slice(1)));
            })
            .join(', ');
        } else {
          return '[]';
        }
      }

      const warning = require('warning');
      if (!warning.mock) {
        throw new Error("toWarn(): Requires `jest.mock('warning')`.");
      }

      const callsCount = warning.mock.calls.length;
      actual();
      const calls = warning.mock.calls.slice(callsCount);

      // Simple case: no explicit expectation.
      if (!expected) {
        const warned = calls.filter(args => !args[0]).length;
        return {
          pass: !(negative ? warned : !warned),
          message:
            `Expected ${negative ? 'not ' : ''}to warn but ` +
            '`warning` received the following calls: ' +
            `${formatActual(calls)}.`,
        };
      }

      // Custom case: explicit expectation.
      if (!Array.isArray(expected)) {
        expected = [expected];
github facebook / relay / packages / react-relay / classic / tools / __mocks__ / RelayTestUtils.js View on Github external
}

      function formatActual(calls) {
        if (calls.length) {
          return calls
            .map(args => {
              return formatArray([!!args[0]].concat(args.slice(1)));
            })
            .join(', ');
        } else {
          return '[]';
        }
      }

      const warning = require('warning');
      if (!warning.mock) {
        throw new Error("toWarn(): Requires `jest.mock('warning')`.");
      }

      const callsCount = warning.mock.calls.length;
      actual();
      const calls = warning.mock.calls.slice(callsCount);

      // Simple case: no explicit expectation.
      if (!expected) {
        const warned = calls.filter(args => !args[0]).length;
        return {
          pass: !(negative ? warned : !warned),
          message:
            `Expected ${negative ? 'not ' : ''}to warn but ` +
            '`warning` received the following calls: ' +
            `${formatActual(calls)}.`,

warning

A mirror of Facebook's Warning

MIT
Latest version published 5 years ago

Package Health Score

70 / 100
Full package analysis