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

Test: Improve MountMustBeDestructuredError error message #28468

Merged
merged 12 commits into from
Jul 7, 2024
Merged
Changes from 9 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
24 changes: 20 additions & 4 deletions code/core/src/preview-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,30 @@ export class StoryStoreAccessedBeforeInitializationError extends StorybookError

export class MountMustBeDestructuredError extends StorybookError {
constructor(public data: { playFunction: string }) {
const transpiled =
/function\s*\*|regeneratorRuntime|asyncToGenerator|_ref|param|_0|__async/.test(
data.playFunction
);

super({
category: Category.PREVIEW_API,
code: 12,
message: dedent`
To use mount in the play function, you must use object destructuring, e.g. play: ({ mount }) => {}.

Instead received:
${data.playFunction}

To use mount in the play function, you must use object destructuring, e.g. play: ({ mount }) => {}.

${
!transpiled
? ''
: dedent`
It seems that your builder is configured to transpile destructuring.
To use the mount prop of the story context, you need to configure your builder to transpile not further than ES2017.
kasperpeulen marked this conversation as resolved.
Show resolved Hide resolved
`
}
More info: https://storybook.js.org/docs/writing-tests/interaction-testing#run-code-before-each-test

Received the following play function:
${data.playFunction}
`,
});
}
Expand Down
Loading