File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -110,6 +110,34 @@ export const LoggedIn: Story = {
110110
111111Before doing this ensure you have mocked the import in the preview file.
112112
113+ ### Play Function Parameters
114+
115+ - The play function has a ` canvas ` parameter that can be used directly with testing-library-like query methods.
116+ - It also has a ` canvasElement ` which is the actual DOM element.
117+ - The ` within ` -function imported from ` storybook/test ` transforms a DOM element to an object with query methods, similar to ` canvas ` .
118+
119+ ** DO NOT** use ` within(canvas) ` - it is redundant because ` canvas ` already has the query methods, ` canvas ` is not a DOM element.
120+
121+ ``` ts
122+ // ✅ Correct: Use canvas directly
123+ play : async ({ canvas }) => {
124+ await canvas .getByLabelText (' Submit' ).click ();
125+ };
126+
127+ // ⚠️ Also acceptable: Use `canvasElement` with `within`
128+ import { within } from ' storybook/test' ;
129+
130+ play : async ({ canvasElement }) => {
131+ const canvas = within (canvasElement );
132+ await canvas .getByLabelText (' Submit' ).click ();
133+ };
134+
135+ // ❌ Wrong: Do NOT use within(canvas)
136+ play : async ({ canvas }) => {
137+ const screen = within (canvas ); // Error!
138+ };
139+ ```
140+
113141### Key Requirements
114142
115143- ** Node.js 20+** , ** TypeScript 4.9+** , ** Vite 5+**
You can’t perform that action at this time.
0 commit comments