From 9ed08d1903efc40925e4900268ccb589e39af518 Mon Sep 17 00:00:00 2001 From: Lukas Siatka Date: Thu, 13 Feb 2020 09:07:33 +0100 Subject: [PATCH] Bugfix: updates cloudwatch query editor test async render to prevent it from throwing error (#22150) --- .../components/QueryEditor.test.tsx | 76 ++-- .../__snapshots__/QueryEditor.test.tsx.snap | 368 +----------------- 2 files changed, 43 insertions(+), 401 deletions(-) diff --git a/public/app/plugins/datasource/cloudwatch/components/QueryEditor.test.tsx b/public/app/plugins/datasource/cloudwatch/components/QueryEditor.test.tsx index 79c61a28e2a..b831d6eadf2 100644 --- a/public/app/plugins/datasource/cloudwatch/components/QueryEditor.test.tsx +++ b/public/app/plugins/datasource/cloudwatch/components/QueryEditor.test.tsx @@ -1,6 +1,7 @@ import React from 'react'; import renderer from 'react-test-renderer'; import { mount } from 'enzyme'; +import { act } from 'react-dom/test-utils'; import { DataSourceInstanceSettings } from '@grafana/data'; import { TemplateSrv } from 'app/features/templating/template_srv'; import { CustomVariable } from 'app/features/templating/all'; @@ -58,45 +59,52 @@ const setup = () => { }; describe('QueryEditor', () => { - it('should render component', () => { - const props = setup(); - const tree = renderer.create().toJSON(); - expect(tree).toMatchSnapshot(); + it('should render component', async () => { + const { act } = renderer; + await act(async () => { + const props = setup(); + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); + }); }); describe('should use correct default values', () => { - it('when region is null is display default in the label', () => { - const props = setup(); - props.query.region = null; - const wrapper = mount(); - expect( - wrapper - .find('.gf-form-inline') - .first() - .find('.gf-form-label.query-part') - .first() - .text() - ).toEqual('default'); + it('when region is null is display default in the label', async () => { + await act(async () => { + const props = setup(); + props.query.region = null; + const wrapper = mount(); + expect( + wrapper + .find('.gf-form-inline') + .first() + .find('.gf-form-label.query-part') + .first() + .text() + ).toEqual('default'); + }); }); - it('should init props correctly', () => { - const props = setup(); - props.query.namespace = null; - props.query.metricName = null; - props.query.expression = null; - props.query.dimensions = null; - props.query.region = null; - props.query.statistics = null; - const wrapper = mount(); - const { - query: { namespace, region, metricName, dimensions, statistics, expression }, - } = wrapper.props(); - expect(namespace).toEqual(''); - expect(metricName).toEqual(''); - expect(expression).toEqual(''); - expect(region).toEqual('default'); - expect(statistics).toEqual(['Average']); - expect(dimensions).toEqual({}); + it('should init props correctly', async () => { + await act(async () => { + const props = setup(); + props.query.namespace = null; + props.query.metricName = null; + props.query.expression = null; + props.query.dimensions = null; + props.query.region = null; + props.query.statistics = null; + const wrapper = mount(); + const { + query: { namespace, region, metricName, dimensions, statistics, expression }, + } = wrapper.props(); + expect(namespace).toEqual(''); + expect(metricName).toEqual(''); + expect(expression).toEqual(''); + expect(region).toEqual('default'); + expect(statistics).toEqual(['Average']); + expect(dimensions).toEqual({}); + }); }); }); }); diff --git a/public/app/plugins/datasource/cloudwatch/components/__snapshots__/QueryEditor.test.tsx.snap b/public/app/plugins/datasource/cloudwatch/components/__snapshots__/QueryEditor.test.tsx.snap index 1f91a53d56d..d977a61df6d 100644 --- a/public/app/plugins/datasource/cloudwatch/components/__snapshots__/QueryEditor.test.tsx.snap +++ b/public/app/plugins/datasource/cloudwatch/components/__snapshots__/QueryEditor.test.tsx.snap @@ -1,369 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`QueryEditor should render component 1`] = ` -Array [ -
- - -
-
-
-
, -
- - -
-
-
-
, -
- - -
-
-
-
, -
- - -
- - - -
-
-
-
-
, -
- - - - -
- - - -
-
-
-
-
, -
-
- -
- -
-
-
- -
- -
-
-
, -
-
- -
- -
-
-
- -
- -
-
- -
- -
-
-
-
-
, -] -`; +exports[`QueryEditor should render component 1`] = `null`;