From 1cbc67144aa161ad612d0a84fd830568b00580e9 Mon Sep 17 00:00:00 2001 From: Sander Date: Mon, 17 Jun 2024 10:27:34 +0200 Subject: [PATCH] docs(ct): format story example code (#31317) --- docs/src/test-components-js.md | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/docs/src/test-components-js.md b/docs/src/test-components-js.md index cdb065347e..7d733230e8 100644 --- a/docs/src/test-components-js.md +++ b/docs/src/test-components-js.md @@ -232,12 +232,14 @@ Let's say you'd like to test following component: ```js title="input-media.tsx" import React from 'react'; -export const InputMedia: React.FC<{ +type InputMediaProps = { // Media is a complex browser object we can't send to Node while testing. - onChange: (media: Media) => void, -}> = ({ onChange }) => { - return <> as any; + onChange(media: Media): void; }; + +export function InputMedia(props: InputMediaProps) { + return <> as any; +} ``` Create a story file for your component: @@ -246,12 +248,14 @@ Create a story file for your component: import React from 'react'; import InputMedia from './import-media'; -export const InputMediaForTest: React.FC<{ - onMediaChange: (mediaName: string) => void, -}> = ({ onMediaChange }) => { - // Instead of sending a complex `media` object to the test, send the media name. - return onMediaChange(media.name)} />; +type InputMediaForTestProps = { + onMediaChange(mediaName: string): void; }; + +export function InputMediaForTest(props: InputMediaForTestProps) { + // Instead of sending a complex `media` object to the test, send the media name. + return props.onMediaChange(media.name)} />; +} // Export more stories here. ``` @@ -265,7 +269,6 @@ test('changes the image', async ({ mount }) => { { mediaSelected = mediaName; - console.log({ mediaName }); }} /> );