You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I would like to be able to mock modules globally, moving the beforeEach call to Preview. This way, I could apply an option passed via globals to mockReturnValue.
Describe the solution you'd like
I want to include a global OS emulation dropdown like this:
// src/path/to/MyStory.stories.tsxexportconstPlayground: Story={beforeEach({ globals }){// @ts-expect-errorisApple.mockReturnValue(globals.os==='mac');},};// .storybook/preview.tsimporttype{Preview}from'@storybook/react';// Problem: subpath import for '#utils' not possible here!// import { isApple } from '#utils' constpreview: Preview={// ..globalTypes: {os: {name: 'OS family',description: 'Applies OS family',defaultValue: 'win',toolbar: {icon: 'memory',items: [{title: 'Microsoft',value: 'win'},{title: 'Apple',value: 'mac'},],},},},// ..parameters: {beforeEach({ globals }){// Problem: See above!// isApple.mockReturnValue(globals.os === 'mac');},}}exportdefaultpreview
Describe alternatives you've considered
Putting beforeEach into every story where OS differences occur
Are you able to assist to bring the feature to reality?
no
Additional context
Especially keybindings differ between OS families, so I need an elegant way to implement a switch/dropdown.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Is your feature request related to a problem? Please describe.
I would like to be able to mock modules globally, moving the
beforeEach
call toPreview
. This way, I could apply an option passed viaglobals
tomockReturnValue
.Describe the solution you'd like
I want to include a global OS emulation dropdown like this:
Describe alternatives you've considered
Putting
beforeEach
into every story where OS differences occurAre you able to assist to bring the feature to reality?
no
Additional context
Especially keybindings differ between OS families, so I need an elegant way to implement a switch/dropdown.
Beta Was this translation helpful? Give feedback.
All reactions