Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: rewrite to use act to increase stability #4163

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(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);
});


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