Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 9, 2025

Migrate Charts v8 and v9 Tests for React 19 Compatibility

This PR migrates tests in both @fluentui/react-charting (Charts v8) and @fluentui/react-charts (Charts v9) from react-test-renderer to @testing-library/react to enable React 19 compatibility. This addresses the requirements outlined in issue #35306.

Changes

Test Migration to @testing-library/react

Charts v8 (@fluentui/react-charting) - Migrated 5 test files:

  • Sparkline.test.tsx
  • HorizontalBarChartWithAxis.test.tsx
  • VerticalBarChart.test.tsx
  • TreeChart.test.tsx
  • VerticalStackedBarChart.test.tsx

Charts v9 (@fluentui/react-charts) - Migrated 5 test files:

  • Sparkline.test.tsx
  • Legends.test.tsx
  • VerticalBarChart.test.tsx
  • VerticalStackedBarChart.test.tsx
  • DonutChart.test.tsx

The migration was necessary because react-test-renderer is not compatible with React 19, and using @testing-library/react ensures proper integration testing across React 17/18/19 through our tooling.

Enabled RIT for react-charting

Removed react-charting from the exclusion list in .github/workflows/pr.yml to enable React Integration Tests (RIT) for both React 17 and 19, ensuring compatibility validation in CI.

Key Migration Patterns

Before:

const component = renderer.create(<Chart data={data} />);
const tree = component.toJSON();
expect(tree).toMatchSnapshot();

After:

const { container } = render(<Chart data={data} />);
expect(container.firstChild).toMatchSnapshot();

For tests using act:

let result: ReturnType<typeof render> | undefined;
act(() => {
  result = render(<Chart data={data} />);
});
expect(result!.container.firstChild).toMatchSnapshot();

All tests use DOM-based assertions and container.firstChild to avoid the extra wrapper div in snapshots, providing more accurate snapshot testing.

Global Test Setup

Added getComputedTextLength mock to the global test setup file (config/tests.js) for v9 charts to handle JSDOM limitations with SVG text measurement. The mock is configurable and writable to allow individual tests to override it if needed.

Testing

✅ All test files in @fluentui/react-charting pass successfully
✅ All test files in @fluentui/react-charts pass successfully
✅ No regressions in existing functionality
✅ Updated snapshots to use container.firstChild for cleaner output
✅ Global getComputedTextLength mock properly configured in test setup

Breaking Changes

None. This is a backward-compatible change that migrates tests to @testing-library/react for better React 19 compatibility.

Related Issues

Fixes #35306

Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature]: Charts v8 React 19 Support</issue_title>
<issue_description>### Area

React Components (@fluentui/react-components)

Describe the feature that you would like added

To support React 19 in both the v8 and v9 Charts packages, we need to address the following issues:

Additional context

No response

Have you discussed this feature with our team

@Hotell

Validations

  • Check that there isn't already an issue that requests the same feature to avoid creating a duplicate.

Priority

High</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #35306

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@dmytrokirpa
Copy link
Contributor

@copilot revert changes in all package.json and change/[...].json files. They are not relevant for this PR


/* eslint-disable @typescript-eslint/no-deprecated */
describe('VerticalBarChart snapShot testing', () => {
const mockGetComputedTextLength = jest.fn().mockReturnValue(100);
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot remove the mock, it shouldn't be required

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 local mocks from VerticalBarChart and VerticalStackedBarChart test files and added a global getComputedTextLength mock to config/tests.js instead. The global mock is configurable and writable to allow tests that need custom behavior to override it. All tests pass successfully. Commit: f7e9c3a

Copy link

github-actions bot commented Oct 16, 2025

📊 Bundle size report

✅ No changes found

Copy link

Pull request demo site: URL

@dmytrokirpa dmytrokirpa force-pushed the copilot/support-react-19-charts-v8 branch from df6f0df to 36101cd Compare October 16, 2025 13:43
@dmytrokirpa dmytrokirpa removed their request for review October 16, 2025 13:43
path: |
tmp/rit/**/cypress/screenshots/**/*.png
retention-days: 1

Choose a reason for hiding this comment

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

🕵🏾‍♀️ visual changes to review in the Visual Change Report

vr-tests-react-components/Card Converged - Selectable 8 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/Card Converged - Selectable.appearance selectable - Filled.normal.chromium.png 16531 Changed
vr-tests-react-components/Card Converged - Selectable.appearance selectable - Filled - Dark Mode.click.chromium.png 9053 Changed
vr-tests-react-components/Card Converged - Selectable.appearance selectable - Filled.click.chromium.png 15083 Changed
vr-tests-react-components/Card Converged - Selectable.appearance selectable - Filled - Dark Mode.normal.chromium.png 8962 Changed
vr-tests-react-components/Card Converged - Selectable.appearance selectable - Filled - Dark Mode.selected.chromium.png 9088 Changed
vr-tests-react-components/Card Converged - Selectable.appearance selectable - Filled.hover.chromium.png 15966 Changed
vr-tests-react-components/Card Converged - Selectable.appearance selectable - Filled.selected.chromium.png 15548 Changed
vr-tests-react-components/Card Converged - Selectable.appearance selectable - Filled - Dark Mode.hover.chromium.png 8956 Changed
vr-tests-react-components/Charts-DonutChart 2 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/Charts-DonutChart.Dynamic - Dark Mode.default.chromium.png 12635 Changed
vr-tests-react-components/Charts-DonutChart.Dynamic.default.chromium.png 27053 Changed
vr-tests-react-components/Positioning 2 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/Positioning.Positioning end.updated 2 times.chromium.png 44 Changed
vr-tests-react-components/Positioning.Positioning end.chromium.png 863 Changed
vr-tests-react-components/TagPicker 1 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/TagPicker.disabled - High Contrast.disabled input hover.chromium.png 1321 Changed
vr-tests-web-components/Avatar 2 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-web-components/Avatar. - Dark Mode.normal.chromium_1.png 298 Changed
vr-tests-web-components/Avatar. - Dark Mode.normal.chromium.png 10381 Changed
vr-tests-web-components/Switch 1 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-web-components/Switch. - Dark Mode.hover.chromium_2.png 92 Changed
vr-tests/Callout 11 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests/Callout.Bottom left edge - RTL.default.chromium.png 2186 Changed
vr-tests/Callout.Beak 25.default.chromium.png 2185 Changed
vr-tests/Callout.Bottom right edge - RTL.default.chromium.png 1114 Changed
vr-tests/Callout.Bottom right edge.default.chromium.png 1120 Changed
vr-tests/Callout.Left bottom edge.default.chromium.png 3123 Changed
vr-tests/Callout.Gap space 25.default.chromium.png 2181 Changed
vr-tests/Callout.No beak.default.chromium.png 2177 Changed
vr-tests/Callout.No callout width specified.default.chromium.png 2126 Changed
vr-tests/Callout.Right top edge.default.chromium.png 1116 Changed
vr-tests/Callout.Top center.default.chromium.png 2113 Changed
vr-tests/Callout.Top left edge.default.chromium.png 2196 Changed
vr-tests/Dropdown 12 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests/Dropdown.Custom Dropdown - RTL.hover.chromium.png 1090 Changed
vr-tests/Dropdown.Required without label.hover.chromium.png 29 Changed
vr-tests/Dropdown.Custom Dropdown - RTL.click.chromium.png 2504 Changed
vr-tests/Dropdown.Custom Dropdown - RTL.default.chromium.png 1828949 Changed
vr-tests/Dropdown.Required.hover.chromium.png 29 Changed
vr-tests/Dropdown.Custom Dropdown - RTL.hover item.chromium.png 2423 Changed
vr-tests/Dropdown.Required without label.click.chromium.png 29 Changed
vr-tests/Dropdown.Required without label.default.chromium.png 1836060 Changed
vr-tests/Dropdown.Required without label.hover item.chromium.png 23 Changed
vr-tests/Dropdown.Required.click.chromium.png 29 Changed
vr-tests/Dropdown.Required.default.chromium.png 1827027 Changed
vr-tests/Dropdown.Required.hover item.chromium.png 23 Changed
vr-tests/Dropdown Disabled 3 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests/Dropdown Disabled.Root.hover.chromium.png 12 Changed
vr-tests/Dropdown Disabled.Root.click.chromium.png 12 Changed
vr-tests/Dropdown Disabled.Root.default.chromium.png 1831344 Changed
vr-tests/Keytip 3 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests/Keytip.Disabled.default.chromium.png 24 Changed
vr-tests/Keytip.Offset.default.chromium.png 86 Changed
vr-tests/Keytip.Root.default.chromium.png 55 Changed
vr-tests/react-charting-GaugeChart 1 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests/react-charting-GaugeChart.Basic.default.chromium.png 2 Changed
vr-tests/react-charting-LineChart 2 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests/react-charting-LineChart.Events.default.chromium.png 17 Changed
vr-tests/react-charting-LineChart.Events - Dark Mode.default.chromium.png 16 Changed
vr-tests/react-charting-MultiStackBarChart 3 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests/react-charting-MultiStackBarChart.Basic_Absolute - Dark Mode.default.chromium.png 363 Changed
vr-tests/react-charting-MultiStackBarChart.Basic_Absolute - RTL.default.chromium.png 343 Changed
vr-tests/react-charting-MultiStackBarChart.Basic_PartToWhole - RTL.default.chromium.png 343 Changed

There were 3 duplicate changes discarded. Check the build logs for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[Feature]: Charts v8 React 19 Support

2 participants