Skip to content

Commit c8ed350

Browse files
authored
Clean test warnings (#1353)
* Prefix unsafe react lifecycle methods with UNSAFE_ * Fix typo in propTypes assignments - ShowcaseButton & ShowcaseDropdown * Mock canvas in react-vis tests * Fix warning in tests about svg elements not being wrapped by a <svg> tag * Fix warningss in test for borders.test.js * Fix warnings about missing key in line-series-canvas.test.js * Fix typo in propTypes assignement for ShowCaseButton * Convert key index to string for LineSeriescanvas
1 parent cce5980 commit c8ed350

33 files changed

+149
-67
lines changed

packages/react-vis/jest.setup.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*eslint-env node*/
22
import jsdom from 'jsdom';
33
import Enzyme from 'enzyme';
4-
54
import Adapter from 'enzyme-adapter-react-16';
5+
66
Enzyme.configure({adapter: new Adapter()});
77

88
global.document = jsdom.jsdom('<body></body>');
@@ -16,3 +16,8 @@ Object.keys(document.defaultView).forEach(function mapProperties(property) {
1616
global.navigator = {
1717
userAgent: 'node.js'
1818
};
19+
20+
/*
21+
* Canvas mocks
22+
*/
23+
HTMLCanvasElement.prototype.getContext = () => {};

packages/react-vis/src/animation.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ class Animation extends PureComponent {
5959
this._updateInterpolator(props);
6060
}
6161

62-
// eslint-disable-next-line react/no-deprecated
63-
componentWillUpdate(props) {
62+
UNSAFE_componentWillUpdate(props) {
6463
this._updateInterpolator(this.props, props);
6564
if (props.onStart) {
6665
props.onStart();

packages/react-vis/src/make-vis-flexible.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ function makeFlexible(Component, isWidthFlexible, isHeightFlexible) {
140140
this.cancelSubscription = subscribeToDebouncedResize(this._onResize);
141141
}
142142

143-
// eslint-disable-next-line react/no-deprecated
144-
componentWillReceiveProps() {
143+
UNSAFE_componentWillReceiveProps() {
145144
this._onResize();
146145
}
147146

packages/react-vis/src/plot/crosshair.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ class Crosshair extends PureComponent {
8282
PropTypes.oneOfType([
8383
PropTypes.number,
8484
PropTypes.string,
85-
PropTypes.object
85+
PropTypes.object,
86+
PropTypes.bool
8687
])
8788
),
8889
series: PropTypes.object,

packages/react-vis/src/plot/series/arc-series.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class ArcSeries extends AbstractSeries {
7474
this.state = {scaleProps};
7575
}
7676

77-
componentWillReceiveProps(nextProps) {
77+
UNSAFE_componentWillReceiveProps(nextProps) {
7878
this.setState({scaleProps: this._getAllScaleProps(nextProps)});
7979
}
8080

packages/react-vis/src/plot/xy-plot.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ class XYPlot extends React.Component {
144144
};
145145
}
146146

147-
// eslint-disable-next-line react/no-deprecated
148-
componentWillReceiveProps(nextProps) {
147+
UNSAFE_componentWillReceiveProps(nextProps) {
149148
const children = getSeriesChildren(nextProps.children);
150149
const nextData = getStackedData(children, nextProps.stackBy);
151150
const {scaleMixins} = this.state;

packages/react-vis/src/treemap/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ class Treemap extends React.Component {
100100
};
101101
}
102102

103-
// eslint-disable-next-line react/no-deprecated
104-
componentWillReceiveProps(props) {
103+
UNSAFE_componentWillReceiveProps(props) {
105104
this.setState({
106105
scales: _getScaleFns(props),
107106
...getInnerDimensions(props, props.margin)

packages/react-vis/tests/components/arc-series.test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ import ArcSeries from 'plot/series/arc-series';
44
import {testRenderWithProps, GENERIC_XYPLOT_SERIES_PROPS} from '../test-utils';
55
import ArcSeriesExample from '../../../showcase/radial-chart/arc-series-example';
66

7-
testRenderWithProps(ArcSeries, GENERIC_XYPLOT_SERIES_PROPS);
7+
testRenderWithProps(ArcSeries, GENERIC_XYPLOT_SERIES_PROPS, true);
88

99
describe('ArcSeries', () => {
1010
test('Showcase Example - ArcSeriesExample', () => {
11-
const $ = mount(<ArcSeriesExample />);
11+
const $ = mount(
12+
<svg>
13+
<ArcSeriesExample />
14+
</svg>
15+
);
1216
expect($.text()).toBe('UPDATE-4-2024-4-2024');
1317
// multiplied by two to account for shadow listeners
1418
expect($.find('.rv-xy-plot__series--arc').length).toBe(4);

packages/react-vis/tests/components/area-series.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {testRenderWithProps, GENERIC_XYPLOT_SERIES_PROPS} from '../test-utils';
77
import AreaChartElevated from '../../../showcase/plot/area-chart-elevated';
88
import AreaChart from '../../../showcase/plot/area-chart';
99

10-
testRenderWithProps(AreaSeries, GENERIC_XYPLOT_SERIES_PROPS);
10+
testRenderWithProps(AreaSeries, GENERIC_XYPLOT_SERIES_PROPS, true);
1111

1212
const AREA_PROPS = {
1313
className: 'area-chart-example',

packages/react-vis/tests/components/axis-title.test.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ describe('AxisTitle', () => {
1616
const props = Object.assign({}, baseProps, {
1717
orientation: BOTTOM
1818
});
19-
const $ = mount(<AxisTitle {...props} />);
19+
const $ = mount(
20+
<svg>
21+
<AxisTitle {...props} />
22+
</svg>
23+
);
2024
const innerGroupHtml = $.find('g > g').html();
2125
expect(innerGroupHtml.includes('text-anchor: end')).toBeTruthy();
2226
expect($.find('text').text()).toBe(baseProps.title);
@@ -27,7 +31,11 @@ describe('AxisTitle', () => {
2731
orientation: TOP,
2832
position: 'start'
2933
});
30-
const $ = mount(<AxisTitle {...props} />);
34+
const $ = mount(
35+
<svg>
36+
<AxisTitle {...props} />
37+
</svg>
38+
);
3139
const innerGroupHtml = $.find('g > g').html();
3240
expect(innerGroupHtml.includes('text-anchor: start')).toBeTruthy();
3341
expect($.find('text').text()).toBe(baseProps.title);
@@ -37,7 +45,11 @@ describe('AxisTitle', () => {
3745
const props = Object.assign({}, baseProps, {
3846
orientation: LEFT
3947
});
40-
const $ = mount(<AxisTitle {...props} />);
48+
const $ = mount(
49+
<svg>
50+
<AxisTitle {...props} />
51+
</svg>
52+
);
4153
const innerGroupHtml = $.find('g > g').html();
4254
expect(innerGroupHtml.includes('text-anchor: end')).toBeTruthy();
4355
expect($.find('text').text()).toBe(baseProps.title);
@@ -48,7 +60,11 @@ describe('AxisTitle', () => {
4860
orientation: RIGHT,
4961
position: 'start'
5062
});
51-
const $ = mount(<AxisTitle {...props} />);
63+
const $ = mount(
64+
<svg>
65+
<AxisTitle {...props} />
66+
</svg>
67+
);
5268
const innerGroupHtml = $.find('g > g').html();
5369
expect(innerGroupHtml.includes('text-anchor: start')).toBeTruthy();
5470
expect($.find('text').text()).toBe(baseProps.title);

0 commit comments

Comments
 (0)