Skip to content

Commit

Permalink
Improve MountMustBeDestructuredError error message
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperpeulen committed Jul 5, 2024
1 parent c59e9bb commit 7f91f3b
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions code/core/src/preview-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,30 @@ export class MountMustBeDestructuredError extends StorybookError {
super();
}

readonly documentation =
'https://storybook.js.org/docs/writing-tests/interaction-testing#run-code-before-each-test';

template() {
const transpiled =
/function\s*\*|regeneratorRuntime|asyncToGenerator|_ref|param|_0|__async/.test(
this.data.playFunction
);

return dedent`
To use mount in the play function, you must use object destructuring, e.g. play: ({ mount }) => {}.
${
!transpiled
? ''
: dedent`
\nIt seems that your builder is configured to transpile destructuring.
To use the mount prop, you need to configure your builder to transpile not further than ES2017.
`
}
Instead received:
${this.data.playFunction}
Received the following play function:
${this.data.playFunction.slice(0, 50)}
`;
}
}
Expand Down

0 comments on commit 7f91f3b

Please sign in to comment.