How to use the jest-snapshot.toMatchSnapshot.bind function in jest-snapshot

To help you get started, we’ve selected a few jest-snapshot 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 igor-dv / jest-specific-snapshot / src / index.js View on Github external
const absoluteSnapshotFile = getAbsolutePathToSnapshot(this.testPath, snapshotFile);

  // store the common state to re-use it in "afterAll" hook.
  commonSnapshotState = this.snapshotState;
  let snapshotState = snapshotsStateMap.get(absoluteSnapshotFile);

  if (!snapshotState) {
    snapshotState = new SnapshotState(absoluteSnapshotFile, {
      updateSnapshot: commonSnapshotState._updateSnapshot,
      snapshotPath: absoluteSnapshotFile,
    });
    snapshotsStateMap.set(absoluteSnapshotFile, snapshotState);
  }

  const newThis = Object.assign({}, this, { snapshotState });
  const patchedToMatchSnapshot = toMatchSnapshot.bind(newThis);

  return patchedToMatchSnapshot(received, testName);
}
github rrweb-io / rrweb / test / integration.ts View on Github external
function matchSnapshot(actual: string, testFile: string, testTitle: string) {
  const snapshotState = new SnapshotState(testFile, {
    updateSnapshot: process.env.SNAPSHOT_UPDATE ? 'all' : 'new',
  });

  const matcher = toMatchSnapshot.bind({
    snapshotState,
    currentTestName: testTitle,
  });
  const result = matcher(actual);
  snapshotState.save();
  return result;
}
github qlik-oss / after-work.js / plugins / chai-plugin-snapshot / src / index.js View on Github external
if (currentTestName === null) {
      throw new Error('Can not find current test name');
    }

    let { snapshotState } = runner.snapshotContexts.get(filename) || {};
    if (!snapshotState) {
      const snapshotResolver = buildSnapshotResolver({
        rootDir: process.cwd(),
      });
      const snapshotPath = snapshotResolver.resolveSnapshotPath(filename);
      snapshotState = new SnapshotState(snapshotPath, {
        updateSnapshot: runner.argv.updateSnapshot ? 'all' : 'new',
      });
      runner.snapshotContexts.set(filename, { currentTestName, snapshotState });
    }
    const matcher = toMatchSnapshot.bind({
      snapshotState,
      currentTestName,
    });
    const result = matcher(this._obj);
    this.assert(
      result.pass,
      result.message,
      result.message,
      result.expected,
      result.report,
    );
  };
};