How to use the jest-snapshot.getSnapshotState 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 storybookjs / storybook / src / test_runner.js View on Github external
const allTestState = {
    added: 0,
    matched: 0,
    unmatched: 0,
    updated: 0,
    obsolete: 0,
  }

  for (const group of filterStorybook(storybook, grep)) {

    const filePath = path.resolve(`${configDir}`, `${group.kind}`);
    console.log(chalk.underline(`${group.kind}`));
    const fakeJasmine = {
      Spec: () => {}
    }
    const state = jestSnapshot.getSnapshotState(fakeJasmine, filePath);
    const snapshot = state.snapshot;

    for (const story of group.stories) {
      state.setSpecName(story.name);
      state.setCounter(0);
      const key = `${story.name}`
      const hasSnapshot = snapshot.has(key);
      const context = { kind: group.kind, story: story.name };
      const tree = story.render(context);
      const renderer = ReactTestRenderer.create(tree);
      const actual = renderer.toJSON()

      if (!snapshot.fileExists() || !hasSnapshot) {
        // If the file does not exist of snapshot of this name is not present
        // add it.
        logState('added', story.name);