Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Update the types for <Money/> (#80)
Browse files Browse the repository at this point in the history
* Update the types for <Money/>

* fix test
  • Loading branch information
frehner committed Nov 23, 2022
1 parent 996a197 commit a776e01
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-needles-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/hydrogen-react': patch
---

Update the TypeScript types for `<Money/>` so that the default rendered element is a `"div"`.
10 changes: 5 additions & 5 deletions packages/react/src/Money.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ describe('<Money />', () => {
expect(screen.getByText(money.amount, {exact: false})).toHaveClass('money');
});

it.todo(`validates props when a component is passed to the 'as' prop`, () => {
it(`validates props when a different Element is passed to the 'as' prop`, () => {
const money = getPrice();
// @ts-expect-error figure out a better component to use here since Link won't be coming to h-ui
render(<Money data={money} as={Link} to="/test" />, {

render(<Money data={money} as="button" disabled />, {
wrapper: ({children}) => (
<ShopifyProvider shopifyConfig={getShopifyConfig()}>
{children}
</ShopifyProvider>
),
});

const element = screen.getByRole('link', {
const element = screen.getByRole('button', {
name: new RegExp(money.amount),
});

expect(element).toHaveAttribute('href', '/test');
expect(element).toHaveAttribute('disabled');
});

it(`removes trailing zeros when the prop is passed`, () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/Money.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type MoneyProps<ComponentGeneric extends React.ElementType> =
* [MoneyV2 object](https://shopify.dev/api/storefront/reference/common-objects/moneyv2) according to the
* `locale` in the `ShopifyProvider` component.
*/
export function Money<ComponentGeneric extends React.ElementType>({
export function Money<ComponentGeneric extends React.ElementType = 'div'>({
data,
as,
withoutCurrency,
Expand Down

0 comments on commit a776e01

Please sign in to comment.