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

fix: replace unreliable setTimeout usage with waitFor #28620

Merged
merged 1 commit into from
Nov 21, 2024
Merged
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
@@ -1,5 +1,5 @@
import React from 'react';
import { fireEvent } from '@testing-library/react';
import { fireEvent, waitFor } from '@testing-library/react';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { renderWithProvider } from '../../../../../test/lib/render-helpers';
Expand Down Expand Up @@ -55,7 +55,7 @@ describe('AddContact component', () => {
expect(getByText('Ethereum public address')).toBeInTheDocument();
});

it('should validate the address correctly', () => {
it('should validate the address correctly', async () => {
const store = configureMockStore(middleware)(state);
const { getByText, getByTestId } = renderWithProvider(
<AddContact {...props} />,
Expand All @@ -64,9 +64,10 @@ describe('AddContact component', () => {

const input = getByTestId('ens-input');
fireEvent.change(input, { target: { value: 'invalid address' } });
setTimeout(() => {
expect(getByText('Recipient address is invalid')).toBeInTheDocument();
}, 600);

await waitFor(() =>
expect(getByText('Recipient address is invalid')).toBeInTheDocument(),
);
Comment on lines +68 to +70
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can findBy* queries here and avoid using the waitFor.

});

it('should get disabled submit button when username field is empty', () => {
Expand Down
Loading