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

Portable stories - Document common use cases and limitations #25879

Closed
Tracked by #25875
yannbf opened this issue Feb 2, 2024 · 0 comments
Closed
Tracked by #25875

Portable stories - Document common use cases and limitations #25879

yannbf opened this issue Feb 2, 2024 · 0 comments
Assignees

Comments

@yannbf
Copy link
Member

yannbf commented Feb 2, 2024

We should improve the documentation of portable stories to provide different use cases, such as:

  • Reusing the play function
  • Using loaders
  • Overwriting globals (e.g. rendering in english/spanish)
  • Asserting spies from mocked args e.g.
  it('onclick handler is called', async () => {
    const onClickSpy = vi.fn();
    render(<Secondary onClick={onClickSpy} />);
    const buttonElement = screen.getByRole('button');
    buttonElement.click();
    expect(onClickSpy).toHaveBeenCalled();
  });

  // or
  it('onclick handler is called', async () => {
    render(<Secondary />);
    const buttonElement = screen.getByRole('button');
    buttonElement.click();
    expect(Secondary.args.onClick).toHaveBeenCalled(); 
  });

// the example above will work as long as the story has a vi.fn defined like so:
import { fn } from '@storybook/test';
CSF2Secondary.args = {
  onClick: fn(),
};

- Asserting events emitted (vue)

As well as limitations, such as:
- Story native formats (vue, svelte) are not supported

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