Skip to content

Commit

Permalink
feat(roll): roll to ToT Playwright (17-06-24) (#1412)
Browse files Browse the repository at this point in the history
  • Loading branch information
playwrightmachine authored Jun 17, 2024
1 parent 99beacc commit b89cafb
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions nodejs/docs/test-components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,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:
Expand All @@ -229,12 +231,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 <InputMedia onChange={media => 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 <InputMedia onChange={media => props.onMediaChange(media.name)} />;
}
// Export more stories here.
```

Expand All @@ -248,7 +252,6 @@ test('changes the image', async ({ mount }) => {
<InputMediaForTest
onMediaChange={mediaName => {
mediaSelected = mediaName;
console.log({ mediaName });
}}
/>
);
Expand Down

0 comments on commit b89cafb

Please sign in to comment.