Skip to content

Commit

Permalink
Merge pull request #28468 from storybookjs/kasper/improve-error-message
Browse files Browse the repository at this point in the history
Test: Improve MountMustBeDestructuredError error message
  • Loading branch information
kasperpeulen authored Jul 7, 2024
2 parents 3a88baa + 5c19998 commit 3861885
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions code/core/src/preview-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,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 must configure your builder to transpile to no earlier than ES2017.
`
}
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

0 comments on commit 3861885

Please sign in to comment.