hydrogen icon indicating copy to clipboard operation
hydrogen copied to clipboard

[BUG] CartTestProviders is not available for testing

Open LewisN opened this issue 3 years ago • 0 comments

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

  1. Add Storybook to a Hydrogen project (v1.5.0 and above)
  2. Create a story rendering the Header.client component from the Hydrogen demo store (or any component that uses the useCart hook and relies on a Cart Context)
  3. 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 Screenshot 2022-11-15 at 15 55 07

Additional context

  • Hydrogen version: 1.5.0+

LewisN avatar Nov 15 '22 22:11 LewisN