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

do not throw an error when composing stories without play functions #25984

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ describe('composeStory', () => {
);
});

it('should throw when executing the play function but the story does not have one', async () => {
it('should not throw when executing the play function but the story does not have one', async () => {
const Story = () => {};
Story.args = {
primary: true,
};

const composedStory = composeStory(Story, meta);
expect(composedStory.play({ canvasElement: null })).rejects.toThrow();
await expect(composedStory.play({ canvasElement: null })).resolves.toBeUndefined();
});

it('should throw an error if Story is undefined', () => {
Expand Down
12 changes: 5 additions & 7 deletions code/lib/preview-api/src/modules/store/csf/portable-stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,12 @@ export function composeStory<TRenderer extends Renderer = Renderer, TArgs extend
argTypes: story.argTypes as StrictArgTypes<TArgs>,
id: story.id,
play: (async (extraContext: ComposedStoryPlayContext<TRenderer, TArgs>) => {
if (story.playFunction === undefined) {
throw new Error('The story does not have a play function. Make sure to add one.');
if (typeof story.playFunction === 'function') {
await story.playFunction({
...context,
...extraContext,
});
}

await story.playFunction({
...context,
...extraContext,
});
}) as unknown as ComposedStoryPlayFn<TRenderer, Partial<TArgs>>,
}
);
Expand Down