* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { act, screen, waitFor } from '@testing-library/react';
+import { act, screen } from '@testing-library/react';
import React from 'react';
import { addGlobalErrorMessage, addGlobalSuccessMessage } from '../../../helpers/globalMessages';
import { renderApp } from '../../../helpers/testReactTestingUtils';
// we render anything, the GlobalMessageContainer is rendered independently from routing
renderApp('sonarqube', <NullComponent />);
- await waitFor(() => {
+ act(() => {
addGlobalErrorMessage('This is an error');
addGlobalSuccessMessage('This was a triumph!');
});
- expect(await screen.findByRole('alert')).toHaveTextContent('This is an error');
+
+ expect(screen.getByRole('alert')).toHaveTextContent('This is an error');
expect(screen.getByRole('status')).toHaveTextContent('This was a triumph!');
// No duplicate message
- await waitFor(() => {
+ act(() => {
addGlobalErrorMessage('This is an error');
});
+
expect(screen.getByRole('alert')).toHaveTextContent(/^This is an error$/);
- await waitFor(() => {
+ act(() => {
addGlobalSuccessMessage('This was a triumph!');
});
expect(await screen.findByRole('status')).toHaveTextContent(
const user = userEvent.setup();
renderProjectManagementApp();
await waitFor(() => expect(ui.row.getAll()).toHaveLength(5));
+ // Should return Promise: (and same for all similar cases below)
+ // await waitFor(() => selectEvent.select(ui.visibilityFilter.get(), ‘visibility.public’));
+ // Can be fixed by migrating ProjectManagementApp to functional component
await waitFor(() => {
selectEvent.select(ui.visibilityFilter.get(), 'visibility.public');
});
// Incorrect login.
await user.type(loginField, 'janedoe');
await user.type(passwordField, 'invalid');
+
+ // We are not waiting for async handler to be done, as we assert that button is disabled immediately after
+ user.click(submitButton);
await waitFor(() => {
- // Don't use userEvent.click() here. This allows us to more easily see the loading state changes.
- submitButton.click();
- expect(submitButton).toBeDisabled(); // Loading
+ expect(submitButton).toBeDisabled();
});
+
await waitFor(() => {
expect(addGlobalErrorMessage).toHaveBeenCalledWith('login.authentication_failed');
});