How to use jest-get-type - 5 common examples

To help you get started, we’ve selected a few jest-get-type 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 ChristopherChudzicki / math3d-react / client / src / utils / testing / matchers.js View on Github external
export function isNearlyEqual(a, b, config = {} ) {
  const {
    numDigits = 6,
    nSamples = 5,
    range = [1, 3]
  } = config

  if (getType(a) !== getType(b)) {
    return false
  }

  switch (getType(a)) {

    case 'number': {
      return Math.abs(a - b) <= 10 ** -numDigits
    }

    case 'array': {
      return a.length === b.length &&
        a.every((item, index) => isNearlyEqual(item, b[index], config))
    }

    case 'function': {
      // by using max arity, we allow that functions of different arity might be
      // nearly equal. For example, x => 5 and (x, y) => 5
      const arity = Math.max(a.length, b.length)
      const [min, max] = range
      const samples = genSamples(min, max, nSamples, arity)
github ChristopherChudzicki / math3d-react / client / src / utils / testing / matchers.js View on Github external
export function isNearlyEqual(a, b, config = {} ) {
  const {
    numDigits = 6,
    nSamples = 5,
    range = [1, 3]
  } = config

  if (getType(a) !== getType(b)) {
    return false
  }

  switch (getType(a)) {

    case 'number': {
      return Math.abs(a - b) <= 10 ** -numDigits
    }

    case 'array': {
      return a.length === b.length &&
        a.every((item, index) => isNearlyEqual(item, b[index], config))
    }

    case 'function': {
      // by using max arity, we allow that functions of different arity might be
github facebook / jest / packages / jest-leak-detector / src / index.ts View on Github external
constructor(value: unknown) {
    if (isPrimitive(value)) {
      throw new TypeError(
        [
          'Primitives cannot leak memory.',
          'You passed a ' + typeof value + ': <' + prettyFormat(value) + '>',
        ].join(' '),
      );
    }

    let weak: typeof import('weak-napi');

    try {
      // eslint-disable-next-line import/no-extraneous-dependencies
      weak = require('weak-napi');
    } catch (err) {
      if (!err || err.code !== 'MODULE_NOT_FOUND') {
        throw err;
github jest-community / jest-extended / src / matchers / toBeDate / predicate.js View on Github external
const isDate = value => getType(value) === 'date' && !isNaN(value);
github razumnyak / vue-div-100vh / src / vue100vh / convertStyle / convertStyle.js View on Github external
function throwOnBadArgs(givenStyle, windowHeight) {
  if (getType(givenStyle) !== 'object' && givenStyle !== undefined)
    throw Error(`style (the first argument) must be an object or undefined`);
  if (typeof windowHeight !== 'number' || windowHeight < 0)
    throw Error('Second argument (windowHeight) must be a non-negative number');
}

jest-get-type

A utility function to get the type of a value

MIT
Latest version published 1 year ago

Package Health Score

88 / 100
Full package analysis

Popular jest-get-type functions

Similar packages