Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose CartTestProviders in public API #2324

Open
wants to merge 1 commit into
base: v1.x-2022-07
Choose a base branch
from

Conversation

LewisN
Copy link

@LewisN LewisN commented Nov 16, 2022

Description

Mock providers were exposed to a public API in PR #2224 but CartTestProviders was not included.

This PR includes CartTestProviders in the public mock providers so it can be used to provide Cart Context in external contexts (e.g. Storybook).

Fixes issue #2323

Usage in Storybook:

import { ComponentMeta, ComponentStory } from '@storybook/react'
import React from 'react'
import ComponentName from './ComponentName.ui'
import { ShopifyTestProviders, CartTestProviders } from '@shopify/hydrogen/testing'

export default {
  title: 'Components/ComponentName',
  component: ComponentName,
  decorators: [],
} as ComponentMeta<typeof ComponentNameUI>

const Template: ComponentStory<typeof ComponentNameUI> = (args) => {
  return (
    <ShopifyTestProviders>
      <CartTestProviders>
        <Component {...args} /> // This component imports import { useCart } from '@shopify/hydrogen'
      </CartTestProviders>
    </ShopifyTestProviders>
  )
}

export const ComponentName = Template.bind({})

Before submitting the PR, please make sure you do the following:

  • Read the Contributing Guidelines
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123)
  • Update docs in this repository according to your change
  • Run yarn changeset add if this PR cause a version bump based on Keep a Changelog and adheres to Semantic Versioning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant