From c31f92b05d974e1d1880efc29d8d2320190916ef Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Wed, 28 Feb 2024 08:24:56 +0100 Subject: [PATCH] test: rewrite to use `act` to increase stability --- .../__tests__/DeploymentConfigOverlaySpec.js | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/client/src/plugins/camunda-plugin/deployment-tool/__tests__/DeploymentConfigOverlaySpec.js b/client/src/plugins/camunda-plugin/deployment-tool/__tests__/DeploymentConfigOverlaySpec.js index da722c1bee..c431920016 100644 --- a/client/src/plugins/camunda-plugin/deployment-tool/__tests__/DeploymentConfigOverlaySpec.js +++ b/client/src/plugins/camunda-plugin/deployment-tool/__tests__/DeploymentConfigOverlaySpec.js @@ -22,6 +22,7 @@ import { merge } from 'min-dash'; import AuthTypes from '../../shared/AuthTypes'; import DeploymentConfigOverlay from '../DeploymentConfigOverlay'; import DeploymentConfigValidator from '../validation/DeploymentConfigValidator'; +import { act } from 'react-test-renderer'; let mounted; @@ -122,7 +123,7 @@ describe('', () => { }); - it('should display hint if token is missing', (done) => { + it('should display hint if token is missing', async () => { // given const configuration = { @@ -145,22 +146,23 @@ describe('', () => { }, mount); // when - instance.setState({ isAuthNeeded: true }); - instance.isOnBeforeSubmit = true; - wrapper.find('.btn-primary').simulate('submit'); + act(() => { + instance.setState({ isAuthNeeded: true }); + instance.isOnBeforeSubmit = true; + }); + + act(() => { + wrapper.find('.btn-primary').simulate('submit'); + }); + + await sleep(200); // then - setTimeout(() => { + act(() => { wrapper.setProps({}); + }); - try { - expect(wrapper.find('.invalid-feedback')).to.have.length(1); - } catch (err) { - return done(err); - } - - return done(); - }, 100); + expect(wrapper.find('.invalid-feedback')).to.have.length(1); }); @@ -794,3 +796,7 @@ class MockValidator extends DeploymentConfigValidator { Object.assign(this, { ...apiStubs }); } } + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); +}