@@ -8,27 +8,46 @@ import { axe, toHaveNoViolations } from 'jest-axe';
88expect . extend ( toHaveNoViolations ) ;
99
1010const originalRAF = window . requestAnimationFrame ;
11+ const originalGetComputedStyle = window . getComputedStyle ;
1112
1213function 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
2947function sharedAfterEach ( ) {
3048 jest . useRealTimers ( ) ;
3149 window . requestAnimationFrame = originalRAF ;
50+ window . getComputedStyle = originalGetComputedStyle ;
3251}
3352
3453const chart1Points = [
@@ -473,6 +492,8 @@ describe.skip('Area chart rendering with date x-axis data', () => {
473492} ) ;
474493
475494describe ( '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 , / g r a p h - a r e a C h a r t / i) ;
478499 // Assert
@@ -483,6 +504,8 @@ describe('Area chart - Subcomponent Area', () => {
483504} ) ;
484505
485506describe ( '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
672693describe ( '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
737760describe ( '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
806831describe ( '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
835862describe ( '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
903932describe ( '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
917948describe ( '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