hydrogen
hydrogen copied to clipboard
[BUG] CartTestProviders is not available for testing
Describe the bug Components that rely on a Cart Context cannot be rendered in Storybook. This error is shown:
Error: Expected a Cart Context, but no Cart Context was found
CartTestProviders already exists as a mock Provider which could resolve this, but it isn't exported by @shopify/hydrogen/testing.
To Reproduce
- Add Storybook to a Hydrogen project (v1.5.0 and above)
- Create a story rendering the Header.client component from the Hydrogen demo store (or any component that uses the
useCarthook and relies on a Cart Context) - Run storybook and try to load the story
Expected behaviour
I should be able to import CartTestProviders from @shopify/hydrogen/testing and use this in a decorator to provide Cart Context (the same way I can with ShopifyTestProviders). Component should render in Storybook without errors.
Screenshots

Additional context
- Hydrogen version: 1.5.0+