Skip to content

Commit

Permalink
test: rewrite to use act to increase stability
Browse files Browse the repository at this point in the history
  • Loading branch information
nikku committed Feb 28, 2024
1 parent bdde3f6 commit d354335
Showing 1 changed file with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -122,7 +123,7 @@ describe('<DeploymentConfigOverlay>', () => {
});


it('should display hint if token is missing', (done) => {
it('should display hint if token is missing', async () => {

// given
const configuration = {
Expand All @@ -145,22 +146,23 @@ describe('<DeploymentConfigOverlay>', () => {
}, 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(100);

// 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);
});


Expand Down Expand Up @@ -794,3 +796,7 @@ class MockValidator extends DeploymentConfigValidator {
Object.assign(this, { ...apiStubs });
}
}

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

0 comments on commit d354335

Please sign in to comment.