Skip to content

Commit

Permalink
Implement more robust waiting for UI updates
Browse files Browse the repository at this point in the history
Replace hard-coded delays with waits for the specific conditions that we
want to check for.
  • Loading branch information
robertknight committed Nov 3, 2021
1 parent 3509a59 commit 2b4b787
Showing 1 changed file with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Config } from '../../config';
import FilePickerApp, { $imports } from '../FilePickerApp';
import { checkAccessibility } from '../../../test-util/accessibility';
import mockImportedComponents from '../../../test-util/mock-imported-components';
import { delay, waitFor } from '../../../test-util/wait';
import { waitFor, waitForElement } from '../../../test-util/wait';

function interact(wrapper, callback) {
act(callback);
Expand Down Expand Up @@ -145,9 +145,6 @@ describe('FilePickerApp', () => {
selectContent(wrapper, 'https://example.com');

await waitFor(() => fakeAPICall.called);
await delay(100);
wrapper.update();

assert.calledWith(fakeAPICall, {
authToken: 'dummyAuthToken',
path: createAssignmentPath,
Expand All @@ -157,7 +154,9 @@ describe('FilePickerApp', () => {
},
});

assert.called(onSubmit);
await waitFor(() => onSubmit.called);

wrapper.update();
checkFormFields(
wrapper,
{
Expand All @@ -180,11 +179,7 @@ describe('FilePickerApp', () => {

selectContent(wrapper, 'https://example.com');

await waitFor(() => fakeAPICall.called);
await delay(100);
wrapper.update();

const errDialog = wrapper.find('ErrorDialog');
const errDialog = await waitForElement(wrapper, 'ErrorDialog');
assert.equal(errDialog.length, 1);
assert.equal(errDialog.prop('error'), error);
});
Expand Down

0 comments on commit 2b4b787

Please sign in to comment.