How to use jest-diff - 10 common examples

To help you get started, we’ve selected a few jest-diff 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 testing-library / jest-dom / src / to-have-style.js View on Github external
function expectedDiff(expected, computedStyles) {
  const received = Array.from(computedStyles)
    .filter(prop => expected[prop])
    .reduce(
      (obj, prop) =>
        Object.assign(obj, {[prop]: computedStyles.getPropertyValue(prop)}),
      {},
    )
  const diffOutput = jestDiff(
    printoutStyles(expected),
    printoutStyles(received),
  )
  // Remove the "+ Received" annotation because this is a one-way diff
  return diffOutput.replace(`${chalk.red('+ Received')}\n`, '')
}
github testing-library / jest-native / src / to-have-style.js View on Github external
function expectedDiff(expected, elementStyles) {
  const received = Object.keys(elementStyles)
    .filter(prop => expected[prop])
    .reduce((obj, prop) => Object.assign(obj, { [prop]: elementStyles[prop] }), {});

  const diffOutput = jestDiff(printoutStyles(expected), printoutStyles(received));
  // Remove the "+ Received" annotation because this is a one-way diff
  return diffOutput.replace(`${chalk.red('+ Received')}\n`, '');
}
github ybonnefond / stubborn / test / matchers / toReplyWith.ts View on Github external
const fail = (message: string, { expected, received }: any = {}) => {
    const extra = expected
      ? diff(expected, received, { expand: this.expand })
      : '';
    return {
      pass: false,
      message: () =>
        `${message}\n${extra}\nRequest received:\n${JSON.stringify(
          response.body,
          null,
          2,
        )}`, // eslint-disable-line no-magic-numbers
    };
  };
github zc910704 / Vue.js-personal-note / www / day6.1.webpack的url-loader与babel / node_modules / @webassemblyjs / helper-buffer / lib / compare.js View on Github external
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.compareArrayBuffers = compareArrayBuffers;

// this are dev dependencies
var diff = require("jest-diff");

var _require = require("jest-diff/build/constants"),
    NO_DIFF_MESSAGE = _require.NO_DIFF_MESSAGE;

var _require2 = require("@webassemblyjs/wasm-parser"),
    decode = _require2.decode;

var oldConsoleLog = console.log;

function compareArrayBuffers(l, r) {
  /**
   * Decode left
   */
  var bufferL = "";

  console.log = function () {
    for (var _len = arguments.length, texts = new Array(_len), _key = 0; _key < _len; _key++) {
      texts[_key] = arguments[_key];
    }
github zc910704 / Vue.js-personal-note / www / day6.1.webpack的url-loader与babel / node_modules / @webassemblyjs / helper-buffer / esm / compare.js View on Github external
// this are dev dependencies
var diff = require("jest-diff");

var _require = require("jest-diff/build/constants"),
    NO_DIFF_MESSAGE = _require.NO_DIFF_MESSAGE;

var _require2 = require("@webassemblyjs/wasm-parser"),
    decode = _require2.decode;

var oldConsoleLog = console.log;
export function compareArrayBuffers(l, r) {
  /**
   * Decode left
   */
  var bufferL = "";

  console.log = function () {
    for (var _len = arguments.length, texts = new Array(_len), _key = 0; _key < _len; _key++) {
      texts[_key] = arguments[_key];
    }
github storybookjs / storybook / src / test_runner / snapshot_runner.js View on Github external
const state = this.state;
    const key = story.name;
    const context = { kind: this.kind, story: story.name };
    const tree = story.render(context);
    const renderer = ReactTestRenderer.create(tree);
    const actual = renderer.toJSON();

    const result = state.match(story.name, actual, key);

    const outcome = this.getOutcome();

    if (outcome !== 'unmatched') {
      return { state: outcome };
    }

    const diffMessage = diff(
      result.expected.trim(),
      result.actual.trim(),
      {
        aAnnotation: 'Snapshot',
        bAnnotation: 'Current story',
      },
    );

    if (this.interactive) {
      const shouldUpdate = await this.confirmUpate(diffMessage);
      if (shouldUpdate) {
        state.update = true;
        state.match(story.name, actual, key);
        state.update = false;
        return { state: 'updated' };
      }
github hmsk / jest-matcher-vue-test-utils / src / matchers / toHaveDispatched.ts View on Github external
const diffs = matched.map((action, i): string | null => {
            return `"${actionType}" action #${i} payloads:\n\n${diff(payload, action.payload, { bAnnotation: "Dispatched" })}`;
          }).join("\n\n");
          message = `"${actionType}" action has been dispatched, but payload isn't matched to the expectation\n\n${diffs}`;
github astralapp / astral / resources / assets / js / __tests__ / utils / setup.js View on Github external
: () => {
          const difference = diff(expected, data, {
            expand: this.expand
          })
          return (
            this.utils.matcherHint('toHaveBeenDispatchedWith', undefined, undefined, options) +
            '\n\n' +
            (difference &&
              `Expected: ${this.utils.printExpected(expected)}\n` + `Received: ${this.utils.printReceived(data)}`)
          )
        }
github zth / graphql-query-test-mock / src / handleErrors.js View on Github external
export function printVariablesDoesNotMatchError(
  queryMockConfig: MockGraphQLConfig,
  shouldMatchOnVariables: boolean,
  operationName: string,
  variables: Variables
): void {
  if (shouldMatchOnVariables) {
    let errorStr = `Variables do not match for operation "${operationName ||
      'unknown'}"`;

    if (queryMockConfig.matchVariables) {
      throw new Error(`${errorStr} due to custom "matchOnVariables" function`);
    } else {
      throw new Error(
        `${errorStr}.\n\nVariables in request VS mocked variables: \n${printDiff(
          variables,
          queryMockConfig.variables
        )}`
      );
    }
  }
}
github ConvertKit / slate-plugins / packages / slate-testing-library / src / index.js View on Github external
const message = () =>
      `Difference:\n${diff(expectedDocument, receivedDocument)}`;
    return { actual: received, message, pass };

jest-diff

Display differences clearly so people can review changes confidently.

MIT
Latest version published 8 months ago

Package Health Score

93 / 100
Full package analysis

Similar packages