How to use the jest-matcher-utils.stringify function in jest-matcher-utils

To help you get started, we’ve selected a few jest-matcher-utils 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 / expect / src / print.ts View on Github external
export const printCloseTo = (
  receivedDiff: number,
  expectedDiff: number,
  precision: number,
  isNot: boolean,
): string => {
  const receivedDiffString = stringify(receivedDiff);
  const expectedDiffString = receivedDiffString.includes('e')
    ? // toExponential arg is number of digits after the decimal point.
      expectedDiff.toExponential(0)
    : 0 <= precision && precision < 20
    ? // toFixed arg is number of digits after the decimal point.
      // It may be a value between 0 and 20 inclusive.
      // Implementations may optionally support a larger range of values.
      expectedDiff.toFixed(precision + 1)
    : stringify(expectedDiff);

  return (
    `Expected precision:  ${isNot ? '    ' : ''}  ${stringify(precision)}\n` +
    `Expected difference: ${isNot ? 'not ' : ''}< ${EXPECTED_COLOR(
      expectedDiffString,
    )}\n` +
    `Received difference: ${isNot ? '    ' : ''}  ${RECEIVED_COLOR(
      receivedDiffString,
    )}`
  );
};
github excitement-engineer / graphql-iso-date / src / utils / __tests__ / formatterTests.js View on Github external
].forEach(([timestamp, dateTimeString]) => {
    it(`serializes Unix timestamp ${stringify(timestamp)} into date-time-string ${dateTimeString}`, () => {
      expect(serializeUnixTimestamp(timestamp)).toEqual(dateTimeString)
    })
  });
github excitement-engineer / graphql-iso-date / src / utils / __tests__ / formatterTests.js View on Github external
].forEach(([date, dateString]) => {
    it(`serializes ${stringify(date)} into date-string ${dateString}`, () => {
      expect(serializeDate(date)).toEqual(dateString)
    })
  });
github excitement-engineer / graphql-iso-date / src / utils / __tests__ / formatterTests.js View on Github external
].forEach(([dateString, date]) => {
    it(`parses date ${stringify(dateString)} into Date ${stringify(date)}`, () => {
      expect(parseDate(dateString)).toEqual(date)
    })
  });
github testing-library / jest-dom / src / to-have-attribute.js View on Github external
function getAttributeComment(name, value) {
  return value === undefined
    ? `element.hasAttribute(${stringify(name)})`
    : `element.getAttribute(${stringify(name)}) === ${stringify(value)}`
}
github testing-library / jest-dom / src / utils.js View on Github external
function display(value) {
  return typeof value === 'string' ? value : stringify(value)
}
github Shopify / quilt / packages / react-testing / src / toReactString.ts View on Github external
return `${key}={null}`;
  }

  if (typeof value === 'string') {
    return `${key}="${value}"`;
  }

  if (typeof value === 'boolean' && value) {
    return value ? `${key}` : `${key}={false}`;
  }

  if (value instanceof Array) {
    return `${key}={${stringify(value, verbosity + 1)}}`;
  }

  return `${key}={${stringify(value, verbosity)}}`;
}
github testing-library / jest-dom / src / to-contain-element.js View on Github external
message: () => {
      return [
        matcherHint(
          `${this.isNot ? '.not' : ''}.toContainElement`,
          'element',
          'element',
        ),
        '',
        receivedColor(`${stringify(container.cloneNode(false))} ${
          this.isNot ? 'contains:' : 'does not contain:'
        } ${stringify(element ? element.cloneNode(false) : element)}
        `),
      ].join('\n')
    },
  }
github testing-library / jest-dom / src / to-have-attribute.js View on Github external
function printAttribute(name, value) {
  return value === undefined ? name : `${name}=${stringify(value)}`
}