Skip to content

Commit 2ca1e39

Browse files
committed
chore(react-charts): migrate to jest v30
1 parent d8534e2 commit 2ca1e39

File tree

22 files changed

+11209
-4439
lines changed

22 files changed

+11209
-4439
lines changed

packages/charts/react-charts/library/src/components/AreaChart/AreaChart.test.tsx

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,46 @@ import { axe, toHaveNoViolations } from 'jest-axe';
88
expect.extend(toHaveNoViolations);
99

1010
const originalRAF = window.requestAnimationFrame;
11+
const originalGetComputedStyle = window.getComputedStyle;
1112

1213
function updateChartWidthAndHeight() {
1314
jest.useFakeTimers();
1415
Object.defineProperty(window, 'requestAnimationFrame', {
1516
writable: true,
1617
value: (callback: FrameRequestCallback) => callback(0),
1718
});
18-
window.HTMLElement.prototype.getBoundingClientRect = () =>
19+
window.Element.prototype.getBoundingClientRect = () =>
1920
({
2021
bottom: 44,
2122
height: 50,
2223
left: 10,
2324
right: 35.67,
2425
top: 20,
2526
width: 650,
27+
x: 10,
28+
y: 20,
29+
toJSON: () => {},
2630
} as DOMRect);
31+
window.getComputedStyle = (element: Element) => {
32+
const style = originalGetComputedStyle(element);
33+
return {
34+
...style,
35+
marginTop: '0px',
36+
marginBottom: '0px',
37+
getPropertyValue: (prop: string) => {
38+
if (prop === 'margin-top' || prop === 'margin-bottom') {
39+
return '0px';
40+
}
41+
return style.getPropertyValue(prop);
42+
},
43+
} as CSSStyleDeclaration;
44+
};
2745
}
2846

2947
function sharedAfterEach() {
3048
jest.useRealTimers();
3149
window.requestAnimationFrame = originalRAF;
50+
window.getComputedStyle = originalGetComputedStyle;
3251
}
3352

3453
const chart1Points = [
@@ -473,6 +492,8 @@ describe.skip('Area chart rendering with date x-axis data', () => {
473492
});
474493

475494
describe('Area chart - Subcomponent Area', () => {
495+
beforeEach(updateChartWidthAndHeight);
496+
afterEach(sharedAfterEach);
476497
testWithoutWait('Should render the Areas with the specified colors', AreaChart, { data: chartData }, container => {
477498
const areas = getById(container, /graph-areaChart/i);
478499
// Assert
@@ -483,6 +504,8 @@ describe('Area chart - Subcomponent Area', () => {
483504
});
484505

485506
describe('Area chart - Subcomponent legend', () => {
507+
beforeEach(updateChartWidthAndHeight);
508+
afterEach(sharedAfterEach);
486509
testWithoutWait(
487510
'Should highlight the corresponding Area on mouse over on legends',
488511
AreaChart,
@@ -627,9 +650,7 @@ describe('AreaChart - Accessibility tests', () => {
627650
test('Should pass accessibility tests', async () => {
628651
const { container } = render(<AreaChart data={chartData} />);
629652
let axeResults;
630-
await act(async () => {
631-
axeResults = await axe(container);
632-
});
653+
axeResults = await axe(container);
633654
expect(axeResults).toHaveNoViolations();
634655
});
635656
});
@@ -670,6 +691,8 @@ const points: LineChartPoints[] = [
670691
];
671692

672693
describe('AreaChart snapShot testing', () => {
694+
beforeEach(updateChartWidthAndHeight);
695+
afterEach(sharedAfterEach);
673696
it('renders Areachart correctly', async () => {
674697
let wrapper = render(<AreaChart data={chartData} />);
675698
expect(wrapper).toMatchSnapshot();
@@ -735,6 +758,8 @@ describe('AreaChart snapShot testing', () => {
735758
});
736759

737760
describe('AreaChart - basic props', () => {
761+
beforeEach(updateChartWidthAndHeight);
762+
afterEach(sharedAfterEach);
738763
it('Should not mount legend when hideLegend true ', () => {
739764
let wrapper = render(<AreaChart data={chartData} hideLegend={true} />);
740765
const hideLegendDOM = wrapper!.container.querySelectorAll('[class^="legendContainer"]');
@@ -804,6 +829,8 @@ describe('AreaChart - basic props', () => {
804829
});
805830

806831
describe('Render calling with respective to props', () => {
832+
beforeEach(updateChartWidthAndHeight);
833+
afterEach(sharedAfterEach);
807834
it('No prop changes', () => {
808835
const props = {
809836
data: { chartTitle: 'AreaChart', lineChartData: chartPoints },
@@ -833,6 +860,8 @@ describe('Render calling with respective to props', () => {
833860
});
834861

835862
describe('AreaChart - mouse events', () => {
863+
beforeEach(updateChartWidthAndHeight);
864+
afterEach(sharedAfterEach);
836865
it('Should render callout correctly on mouseover', () => {
837866
let wrapper = render(<AreaChart data={chartData} />);
838867
const bars = wrapper.container.querySelectorAll('rect');
@@ -901,6 +930,8 @@ describe('AreaChart - mouse events', () => {
901930
});
902931

903932
describe('Render empty chart aria label div when chart is empty', () => {
933+
beforeEach(updateChartWidthAndHeight);
934+
afterEach(sharedAfterEach);
904935
it('No empty chart aria label div rendered', () => {
905936
let wrapper = render(<AreaChart data={chartData} />);
906937
const renderedDOM = wrapper!.container.querySelectorAll('[aria-label="Graph has no data to display"]');
@@ -915,6 +946,8 @@ describe('Render empty chart aria label div when chart is empty', () => {
915946
});
916947

917948
describe('Area chart rendering with duplicate values', () => {
949+
beforeEach(updateChartWidthAndHeight);
950+
afterEach(sharedAfterEach);
918951
testWithoutWait(
919952
'Should return the correct dataset for duplicate values',
920953
AreaChart,

0 commit comments

Comments
 (0)