Skip to content

Migrate PointerBox tests from Jest to Vitest with computed style assertions #6407

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

Merged
merged 5 commits into from
Aug 4, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 28, 2025

This PR migrates the PointerBox component tests from Jest to Vitest as part of the broader test suite migration effort, replacing snapshot tests with computed style assertions for better test reliability.

Changes Made

  • Updated configuration files: Added PointerBox to the Vitest browser config include list and excluded it from Jest's modulePathIgnorePatterns
  • Migrated test imports: Replaced Jest-specific imports with Vitest (describe, expect, it) and @testing-library/react (render)
  • Removed Jest-specific utilities:
    • Removed behavesAsComponent usage (component behavior tests)
    • Removed checkExports usage (module export validation)
    • Removed axe violations test with toHaveNoViolations (accessibility testing)
  • Fixed theme context issues: Used ThemeProvider wrapper for tests that require styled-components theme context
  • Replaced snapshot tests with computed style assertions: Instead of brittle DOM snapshots, tests now verify actual CSS properties:
    • Border color tests check borderColor CSS property equals rgb(207, 34, 46) for danger.emphasis
    • Background color tests check backgroundImage CSS property contains the expected color
    • Removed basic rendering snapshot test as it provided limited value

Test Coverage

All 5 tests are passing and now provide more reliable assertions:

  • ✅ Border color via borderColor prop (backwards compatibility)
  • ✅ Border color via sx prop
  • ✅ Background color via bg prop (backwards compatibility)
  • ✅ Background color via sx prop
  • ✅ Background color consistency between bg prop and sx prop

The migration improves test reliability by checking actual computed styles rather than DOM structure, making tests less brittle to unrelated markup changes.

Fixes #6390.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copy link

changeset-bot bot commented Jul 28, 2025

⚠️ No Changeset found

Latest commit: b3ddae9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@Copilot Copilot AI changed the title [WIP] Update PointerBox tests from Jest to Vitest Migrate PointerBox tests from Jest to Vitest Jul 28, 2025
@Copilot Copilot AI requested a review from joshblack July 28, 2025 20:14
Copilot finished work on behalf of joshblack July 28, 2025 20:14
Copy link
Member

@joshblack joshblack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot make sure to also pull in the latest changes from main and address merge conflicts

})

it('applies the border color via "borderColor" prop for backwards compatibility', () => {
expect(render(<PointerBox borderColor="danger.emphasis" />)).toMatchSnapshot()
expect(render(<PointerBox borderColor="danger.emphasis" theme={theme} />)).toMatchSnapshot()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update this test from a snapshot test to one that is checking that the border color is set correctly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this test to check that the border color is set correctly using computed styles instead of snapshots. Now verifies borderColor CSS property is rgb(207, 34, 46) for danger.emphasis. Commit b3ddae9

})

it('applies the border color via sx prop', () => {
expect(render(<PointerBox sx={{borderColor: 'danger.emphasis'}} />)).toMatchSnapshot()
expect(render(<PointerBox sx={{borderColor: 'danger.emphasis'}} theme={theme} />)).toMatchSnapshot()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update this test from a snapshot test to one that is checking that the border color is set correctly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this test to check that the border color is set correctly using computed styles instead of snapshots. Now verifies borderColor CSS property is rgb(207, 34, 46) for danger.emphasis. Commit b3ddae9

const {container} = HTMLRender(<PointerBox />)
const results = await axe.run(container)
expect(results).toHaveNoViolations()
expect(render(<PointerBox theme={theme} />)).toMatchSnapshot()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the basic rendering snapshot test as requested. Commit b3ddae9

<PointerBox bg="danger.emphasis" />
</ThemeProvider>,
),
).toMatchSnapshot()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update this test from a snapshot test to one that is checking the background color

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this test to check the background color using computed styles instead of snapshots. Now verifies backgroundImage CSS property contains the expected color rgb(207, 34, 46) for danger.emphasis. Commit b3ddae9

})

it('applies the background color via sx prop', () => {
expect(render(<PointerBox sx={{bg: 'danger.emphasis'}} />)).toMatchSnapshot()
expect(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update this test from a snapshot test to one that is checking the background color

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this test to check the background color using computed styles instead of snapshots. Now verifies backgroundImage CSS property contains the expected color rgb(207, 34, 46) for danger.emphasis. Commit b3ddae9

Copy link
Member

@joshblack joshblack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot pull in the latest changes from main and resolve merge conflicts. Also address the comments in the previous review

Copy link
Contributor Author

Copilot AI commented Jul 31, 2025

@copilot pull in the latest changes from main and resolve merge conflicts. Also address the comments in the previous review

✅ Pulled in latest changes from main and resolved merge conflicts in both config files. ✅ Addressed all review comments - removed snapshot test and converted remaining tests to check computed CSS properties. All tests passing. Commit b3ddae9

@Copilot Copilot AI changed the title Migrate PointerBox tests from Jest to Vitest Migrate PointerBox tests from Jest to Vitest with computed style assertions Jul 31, 2025
@Copilot Copilot AI requested a review from joshblack July 31, 2025 16:51
Copilot finished work on behalf of joshblack July 31, 2025 16:51
@joshblack joshblack marked this pull request as ready for review July 31, 2025 16:53
@Copilot Copilot AI review requested due to automatic review settings July 31, 2025 16:53
@joshblack joshblack requested a review from a team as a code owner July 31, 2025 16:53
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR migrates the PointerBox component tests from Jest to Vitest as part of the broader test suite migration effort, improving test reliability by replacing DOM snapshots with computed style assertions.

  • Migrated test framework from Jest to Vitest with @testing-library/react
  • Replaced brittle snapshot tests with computed style assertions that verify actual CSS properties
  • Removed Jest-specific utilities and added ThemeProvider wrapper for styled-components context

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
packages/react/vitest.config.browser.mts Added PointerBox tests to Vitest browser config include list
packages/react/src/PointerBox/snapshots/PointerBox.test.tsx.snap Removed all Jest snapshot files as they're replaced by computed style tests
packages/react/src/PointerBox/PointerBox.test.tsx Complete migration from Jest to Vitest with computed style assertions replacing snapshots
packages/react/jest.config.js Excluded PointerBox from Jest modulePathIgnorePatterns to prevent conflicts

@github-actions github-actions bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Jul 31, 2025
Copy link
Contributor

👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks!

@joshblack joshblack added the skip changeset This change does not need a changelog label Jul 31, 2025
Copy link
Contributor

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 89.58 KB (0%)
packages/react/dist/browser.umd.js 89.57 KB (0%)

@pksjce pksjce added this pull request to the merge queue Aug 4, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 4, 2025
@joshblack joshblack added this pull request to the merge queue Aug 4, 2025
Merged via the queue into main with commit c7dfdcc Aug 4, 2025
46 of 47 checks passed
@joshblack joshblack deleted the copilot/fix-6390 branch August 4, 2025 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm skip changeset This change does not need a changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update PointerBox tests from Jest to Vitest
3 participants