Skip to content

Commit b08a8b6

Browse files
committed
🤖 fix(test-runner): hide theme toggle in stories with play functions to avoid button conflicts
When test-runner executes stories with interaction tests, the manual StorybookThemeToggle button was appearing alongside component buttons, causing "Found multiple elements" errors when querying by role. This adds a check for context.parameters?.play to hide the toggle button in any story that has an interaction test, preventing button name collisions (e.g., both ToggleGroup's 'Dark' button and the toggle's '🌙 Dark' button matching /dark/i). Fixes: ToggleGroup:Two Options dark/light test failures
1 parent e637aa5 commit b08a8b6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

‎.storybook/preview.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,12 @@ const preview: Preview = {
111111
(Story, context) => {
112112
const mode = context.globals.theme as ThemeMode | undefined;
113113
const resolved = syncStorybookTheme(mode);
114+
// Hide toggle if story has a play function (interaction test) to avoid button conflicts
115+
const hasInteractionTest = !!context.parameters?.play;
114116
return (
115117
<ThemeProvider>
116118
<Story />
117-
{!mode && !isE2ETestEnv() && (
119+
{!mode && !isE2ETestEnv() && !hasInteractionTest && (
118120
<StorybookThemeToggle initialTheme={resolved} />
119121
)}
120122
</ThemeProvider>

0 commit comments

Comments
 (0)