Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[addon-storyshots] Warning: DeprecationWarning: \storyFn\ is deprecated and will be removed in Storybook 7.0 appears in all storyshots on version 6.1.16 #13815

Closed
Kryword opened this issue Feb 4, 2021 · 1 comment

Comments

@Kryword
Copy link

Kryword commented Feb 4, 2021

Describe the bug
A warning is being shown when using initSnapshots with jest with the following message: Warning: DeprecationWarning: `storyFn` is deprecated and will be removed in Storybook 7.0.
With this link as helping message: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-storyfn

Doing a bit of research, I detected this is due to how story.render method is being set by the storyshots addon. It seems that this method is set to story.storyFn instead of the newer API, story.unboundStoryFn. And when story is rendered, that method is executed generating this warning.

To Reproduce
Steps to reproduce the behavior:

  1. Create a initStoryshots jest test, with at least one valid story.
  2. Execute this initStoryshots jest test.
  3. Check terminal, a console.error with the warnings will be shown.

Expected behavior
No deprecation warning should appear when running initSnapshots if stories are alright.

Code snippets

initStoryshots({
  configPath: confDir,
  stories2snapsConverter: new CustomStories2SnapsConverter(),
  // create a snapshot per story instead of one for all of them
  test: ({ story, context, done }) => {
    const filename = converter.getSnapshotFileName(context);

    // Necessary unboundStoryFn to avoid this warning:
    // This shouldn't be necessary once storyFn method is removed in Storybook 7.0
    // When that happens, story.render, should be enough
    const renderContext = await story.applyLoaders();
    const renderer = create(story.unboundStoryFn(renderContext)); // This was previously create(story.render), which failed with that console warning

    // eslint-disable-next-line jest/no-standalone-expect
    expect(renderer.toJSON()).toMatchSpecificSnapshot(filename);
    renderer.unmount();
  }
});

System
Environment Info:

  System:
    OS: Linux 5.8 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
  Binaries:
    Node: 14.15.3 - ~/.nvm/versions/node/v14.15.3/bin/node
    npm: 6.14.9 - ~/.nvm/versions/node/v14.15.3/bin/npm
  Browsers:
    Chrome: 88.0.4324.146
    Firefox: 85.0

Additional context
Let me know if there's something missing in this bug report and if it is necessary to provide more context. I'm open to help with what I can.

I would also highly recommend start checking here: https://github.com/storybookjs/storybook/blob/next/addons/storyshots/storyshots-core/src/api/index.ts#L61
Where this render = storyFn is set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants