How to use warning - 10 common examples

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 salesforce / design-system-react / utilities / warning / future-property.js View on Github external
future = function(control, propValue, newProp, comment) {
		const additionalComment = comment ? ` ${comment}` : '';
		if (!hasWarned[control + newProp]) {
			/* eslint-disable max-len */
			warning(
				!propValue,
				`[Design System React] \`${newProp}\` of ${control} is not implemented yet. Please check future releases for \`${newProp}\`.${additionalComment}`
			);
			/* eslint-enable max-len */
			hasWarned[control + newProp] = !!propValue;
		}
	};
}
github Yoctol / bottender / packages / bottender-handlers / src / LineHandler.js View on Github external
if (args.length < 2) {
      const [handler]: [FunctionalHandler | Builder] = (args: any);

      this.on(context => context.event.isPayload, handler);
    } else {
      // eslint-disable-next-line prefer-const
      let [pattern, handler]: [
        Pattern,
        FunctionalHandler | Builder
      ] = (args: any);

      if (handler.build) {
        handler = handler.build();
      }

      warning(
        typeof pattern === 'function' ||
          typeof pattern === 'string' ||
          pattern instanceof RegExp,
        `'onPayload' only accepts string, regex or function, but received ${typeof pattern}`
      );

      if (typeof pattern === 'function') {
        const predicate: Predicate = pattern;
        this.on(
          context =>
            context.event.isPayload &&
            predicate(context.event.payload, context),
          handler
        );
      } else {
        if (pattern instanceof RegExp) {
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 6 years ago

Package Health Score

73 / 100
Full package analysis