gebeto / storybook-addon-manual-mocks

Manual Mocks addon for Storybook
https://www.npmjs.com/package/storybook-addon-manual-mocks
MIT License
6 stars 0 forks source link

Docs not clear if stories not co-located with component #18

Open zz-james opened 3 months ago

zz-james commented 3 months ago

Hi At my workplace the storybook stories are all in their own 'stories' folder.

This means that reading the 'How to use' sectioin of the docs, is ambiguos for me, if the folder path for the mock is mocks then does this live alongside the 'stories' or alongside the 'component'

I've tried both, and at the moment neither work, but I would like to make sure I have it right before further attempts to fix it.

Many thanks

James

gebeto commented 3 months ago

Hey, it should be alongside with the things you are trying to mock

for example if you have some query hook which is importing api function:

import { someQuery } from './someQuery';

const useSomeQuery = () => {
  return useQuery(() => someQuery(...));
}

you need to create __mocks__ in this direction, to mock the ./someQuery import. You need to create __mocks__/someQuery.ts in current directory

This addon is just adding __mocks__ prefix to all your imports, and checking if there are any mock exists for the prefix. Think about it like that.

Screenshot 2024-05-21 at 14 47 06
zz-james commented 3 months ago

everything is working now, thank you.