fix 'window.ResizeObserver is not a constructor' issue

Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
This commit is contained in:
Augustin Husson 2021-09-02 14:46:46 +02:00
parent 5d29b7b6f7
commit 242d459685
4 changed files with 696 additions and 231 deletions

File diff suppressed because it is too large Load diff

View file

@ -24,11 +24,9 @@
"codemirror-promql": "^0.17.0",
"css.escape": "^1.5.1",
"downshift": "^3.4.8",
"enzyme-to-json": "^3.6.2",
"i": "^0.3.6",
"jquery": "^3.5.1",
"jquery.flot.tooltip": "^0.9.0",
"jsdom": "^17.0.0",
"moment": "^2.24.0",
"moment-timezone": "^0.5.23",
"popper.js": "^1.14.3",
@ -85,7 +83,9 @@
"@typescript-eslint/eslint-plugin": "4.x",
"@typescript-eslint/parser": "4.x",
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.3",
"canvas": "^2.8.0",
"enzyme": "^3.11.0",
"enzyme-to-json": "^3.6.2",
"eslint": "7.x",
"eslint-config-prettier": "^8.3.0",
"eslint-config-react-app": "^6.0.0",

View file

@ -9,6 +9,20 @@ describe('Graph', () => {
beforeAll(() => {
jest.spyOn(window, 'requestAnimationFrame').mockImplementation((cb: any) => cb());
});
// fix coming from https://github.com/maslianok/react-resize-detector#testing-with-enzyme-and-jest
beforeEach(() => {
window.ResizeObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
}));
});
afterEach(() => {
window.ResizeObserver = ResizeObserver;
jest.restoreAllMocks();
});
describe('data is returned', () => {
const props: any = {
queryParams: {

View file

@ -67,7 +67,7 @@ class Graph extends PureComponent<GraphProps, GraphState> {
selectedExemplarLabels: { exemplar: {}, series: {} },
};
componentDidUpdate(prevProps: GraphProps) {
componentDidUpdate(prevProps: GraphProps): void {
const { data, stacked, useLocalTime, showExemplars } = this.props;
if (prevProps.data !== data) {
this.selectedSeriesIndexes = [];
@ -134,7 +134,9 @@ class Graph extends PureComponent<GraphProps, GraphState> {
this.destroyPlot();
}
plot = (data: (GraphSeries | GraphExemplar)[] = [...this.state.chartData.series, ...this.state.chartData.exemplars]) => {
plot = (
data: (GraphSeries | GraphExemplar)[] = [...this.state.chartData.series, ...this.state.chartData.exemplars]
): void => {
if (!this.chartRef.current) {
return;
}