Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

feat: support CSF3 format #37

Merged
merged 3 commits into from
Jul 15, 2021
Merged

feat: support CSF3 format #37

merged 3 commits into from
Jul 15, 2021

Conversation

yannbf
Copy link
Member

@yannbf yannbf commented Jul 11, 2021

Issue: #31

Add support for CSF3

Release Notes

Features

Storybook released CSF3, where the story can also be an object. This is now supported in @storybook/testing-react. CSF3 also brings a new function called play, where you can write automated interactions to the story.

In @storybook/testing-react, the play does not run automatically for you, but rather comes in the returned component, and you can execute it as you please.

Consider the following example:

export const InputFieldFilled: Story<InputFieldProps> = {
  play: async () => {
    await userEvent.type(screen.getByRole('textbox'), 'Hello world!');
  },
};

You can use the play function like this:

const { InputFieldFilled } = composeStories(stories);

test('renders with play function', async () => {
  render(<InputFieldFilled />);

  // play an interaction that fills the input
  await InputFieldFilled.play!();

  const input = screen.getByRole('textbox') as HTMLInputElement;
  expect(input.value).toEqual('Hello world!');
});
📦 Published PR as canary version: 0.0.19--canary.37.ed1f139.0

✨ Test out this PR locally via:

npm install @storybook/testing-react@0.0.19--canary.37.ed1f139.0
# or 
yarn add @storybook/testing-react@0.0.19--canary.37.ed1f139.0

- Add support for stories using object notation
@yannbf yannbf force-pushed the feat/support-csf3-format branch from 0758324 to 24ee251 Compare July 11, 2021 23:17
@loeck
Copy link

loeck commented Jul 12, 2021

Thanks a lot for this PR, look good on my project with 0.0.19--canary.37.24ee251.0 now 🙏 (only few simple tests, so maybe I don't handle lot of cases)

@yannbf
Copy link
Member Author

yannbf commented Jul 13, 2021

Thanks a lot for this PR, look good on my project with 0.0.19--canary.37.24ee251.0 now 🙏 (only few simple tests, so maybe I don't handle lot of cases)

Thank you for trying it out! I'll be updating this PR soon to support CSF3 types, I'll keep you posted!

@benbender
Copy link

benbender commented Jul 15, 2021

Same for me - works like a charm (besides the type-problem). Thank you for your work! 🥇

@yannbf yannbf merged commit e263e32 into main Jul 15, 2021
@yannbf yannbf deleted the feat/support-csf3-format branch July 15, 2021 22:23
@yannbf
Copy link
Member Author

yannbf commented Jul 15, 2021

@loeck @benbender thank you so much!! both for using the lib and for helping out testing. Support like yours is what gives me energy to keep improving the library ❤️

0.0.21 has been released and it includes proper typings. Should work well, but please let me know if you encounter any issues :)

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

Successfully merging this pull request may close these issues.

3 participants