-
Notifications
You must be signed in to change notification settings - Fork 323
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
Migrate tests for AddToCart button to Vite #1899
Conversation
In replacing the old providers, this is one way of doing it now with RTL. Not sure if this is better or not, but it does seem more clear to me?
We detected some changes in |
packages/hydrogen/src/components/AddToCartButton/tests/AddToCart.vitest.tsx
Show resolved
Hide resolved
{ | ||
wrapper: ({children}) => ( | ||
<CartTestProviders | ||
cartConfig={{linesAdd: mockLinesAdd, cart: {id: '456'}}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In more complicated situations, it's clear what props we're passing to the Provider to overwrite things
@@ -0,0 +1,95 @@ | |||
import React from 'react'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of this file is taking what is found in
import {mountWithProviders} from '../../../utilities/tests/shopifyMount.js';
import {mountWithCartProvider} from '../../CartProvider/tests/utilities.js';
and combining them into a new file. The reason for the new file is that the version of shopify's testing library that we have isn't compatible with Vitest, and there are issues where it's in the import path of a Vitest file.
} | ||
); | ||
|
||
expect(screen.getByRole('button')).toHaveAttribute('class', 'bg-blue-600'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that in these tests, we want to getByRole instead of using a testId
@cartogram @mrkldshv @lordofthecactus Would like your thoughts on this one! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left one minor comment. Everything looks good to me!
packages/hydrogen/src/components/AddToCartButton/tests/AddToCart.vitest.tsx
Show resolved
Hide resolved
Really, there's no need to add a level of abstraction when we can just do it directly.
Reduced a layer of abstraction - the goal is to make these tests easy to read and understand, so personally I think removing the |
render( | ||
<CartTestProviders | ||
cartProviderValues={{linesAdd: mockLinesAdd, cart: {id: '456'}}} | ||
> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
easy to customize, and easy to tell what provider is being used. Just render directly instead of using wrapper
<ProductOptionsProvider data={product}> | ||
<AddToCartButton variantId={null}>Add to cart</AddToCartButton> | ||
</ProductOptionsProvider>, | ||
{wrapper: CartTestProviders} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When customization isn't needed, then we can use wrapper
if you want
Description
In replacing the old providers, this is one way of doing it now with RTL. Not sure if this is better or not, but it does seem more clear to me?
Part of #670
Additional context
Before submitting the PR, please make sure you do the following:
fixes #123
)yarn changeset add
if this PR cause a version bump based on Keep a Changelog and adheres to Semantic Versioning