[Help] Trigger exported function #255
-
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
To my knowledge, Storybook doesn't have this kind of control, where you can create a button to emit those events(?). You'd have to define those triggers (e.g., buttons) by yourself. Either inside the component, which is the subject/target of the CC @JReinhold Could you confirm that? What can be done to see those event handlers(?) being emitted is defining actions. |
Beta Was this translation helpful? Give feedback.
-
You have to set up your story to trigger it similar to how it would be triggered in the actual application. Without knowing the internals of the component, how it actually triggers the function, it's hard to say how you could do that. |
Beta Was this translation helpful? Give feedback.
-
Hey, <script module>
import { defineMeta } from '@storybook/addon-svelte-csf';
import Log from '$lib/Log.svelte';
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
const { Story } = defineMeta({
title: 'Log',
component: Log,
tags: ['autodocs']
});
let log = undefined;
</script>
<Story name="Default" args={{ }}/>
<Story name="With Interactions" id="interactions">
<button on:click={() => log.logEvent('Test')}>Log event</button>
<button on:click={() => log.logEvent('Test', new Date('2024-01-01'))}>Log event with time</button>
<button on:click={() => log.clearLog()}>Clear</button>
<br/>
<Log bind:this={log}/>
</Story> |
Beta Was this translation helpful? Give feedback.
Hey,
I found a way to interact with the Component.
I was looking for such an way, and was not realizing that the file where I was defining the story, is also a svelte file, which I can use like all other files.