nandorojo / dripsy

🍷 Responsive, unstyled UI primitives for React Native + Web.
https://dripsy.xyz
MIT License
1.98k stars 77 forks source link

Mocking dripsy? #252

Closed wezter96 closed 1 year ago

wezter96 commented 1 year ago

Do you have any suggestions on what should be done regarding mocking and such with dripsy in unit tests?

I have tests that seem to fail because of theme not being defined and if I mocked that then I got the same issues regarding styled. TypeError: Cannot read properties of null (reading 'theme') and if I mock my theme I get: TypeError: (0 , _dripsy.styled)(...) is not a function

image image

jcamden commented 1 year ago

I'm having a similar issue while trying to use a dripsy component in a Storybook story:

TypeError: Cannot read properties of null (reading 'theme')
    at Wrapped (create-themed-component.tsx:1:1)

Were you ever able to figure out what was needed here?

ryee-dev commented 1 year ago

Also having this issue 😢

nandorojo commented 1 year ago

That error indicates that the provider isn’t present above in the component tree…

jcamden commented 1 year ago

@nandorojo , you rock. With your comment, it took me all of 30 seconds to figure it out and create a decorator to wrap my Storybook stories with the Dripsy component. Hot reloaded and that was that.

For the jest issue above, I think you'd pretty much want the same thing. Probably something like,

const renderWithDripsy = (component) => render(<Dripsy>{component}</Dripsy>)
ryee-dev commented 1 year ago

@nandorojo Woooo I feel dumb haha thanks!

nandorojo commented 1 year ago

🤝