我目前正在努力为我的一个组件完成 React 故事中的一个故事:(下图)
\n我的组件从父组件接收一个 props、一个布尔值和一个修改该布尔值的函数。当我单击按钮时,它应该更改此布尔值的值(从 false 到 true 或从 true 到 false)。\n我似乎无法在故事书上测试此行为。我不知道我是否以正确的方式做事,但似乎不可能将函数从我的 .Stories 文件代码传递到我的组件来测试它。
\n我的问题是:我是否以正确的方式做事,故事书是为这种测试而编写的吗?
\n故事文件代码:
\nimport React from 'react';\nimport { ComponentStory, ComponentMeta } from '@storybook/react';\nimport { ModelCard } from './';\n\nexport default {\n title: 'ModelCard',\n component: ModelCard,\n argTypes: {\n yearProduct: { control : 'text'},\n ecoDesigned: { control: 'boolean'},\n titleProduct: {control: 'text'},\n photoProduct: {control: 'text'},\n setEcoDesigned: {action: 'clicked'}\n }\n} as ComponentMeta<typeof ModelCard>;\n\nconst Template: ComponentStory<typeof ModelCard> = (args) => <ModelCard {...args}/>;\nexport const ModelCardCompleteControls = Template.bind({});\nModelCardCompleteControls.args = {\n yearProduct: …Run Code Online (Sandbox Code Playgroud)