* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { screen } from '@testing-library/react';
+import { act, screen, waitFor } from '@testing-library/react';
import { noop } from 'lodash';
import { render, renderWithRouter } from '../../helpers/testUtils';
import {
await user.hover(screen.getByRole('menuitem'));
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument();
- jest.runAllTimers();
+ act(() => {
+ jest.runAllTimers();
+ });
expect(screen.getByRole('tooltip')).toBeVisible();
await user.unhover(screen.getByRole('menuitem'));
expect(screen.getByRole('tooltip')).toBeVisible();
- jest.runAllTimers();
- expect(screen.queryByRole('tooltip')).not.toBeInTheDocument();
+ act(() => {
+ jest.runAllTimers();
+ });
+ await waitFor(() => {
+ expect(screen.queryByRole('tooltip')).not.toBeInTheDocument();
+ });
});
function renderDropdownMenu() {
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { screen } from '@testing-library/react';
+import { act, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { formatISO, parseISO } from 'date-fns';
import { byRole } from '../../../../../src/main/js/helpers/testSelector';
await user.click(screen.getByRole('textbox', { name: 'from' }));
- expect(nav.get()).toBeInTheDocument();
+ const fromNav = nav.get();
+ expect(fromNav).toBeInTheDocument();
await user.click(nav.byRole('button', { name: 'previous_month_x' }).get());
await user.click(screen.getByText('7'));
- expect(nav.query()).not.toBeInTheDocument();
+ expect(fromNav).not.toBeInTheDocument();
expect(onChange).toHaveBeenCalled();
const { from } = onChange.mock.calls[0][0]; // first argument
onChange.mockClear();
- jest.runAllTimers();
+ act(() => {
+ jest.runAllTimers();
+ });
const previousButton = nav.byRole('button', { name: 'previous_month_x' });
const nextButton = nav.byRole('button', { name: 'next_month_x' });
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { screen, waitFor } from '@testing-library/react';
+import { act, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React, { useContext } from 'react';
import { Route } from 'react-router-dom';
});
afterEach(() => {
+ jest.runOnlyPendingTimers();
jest.useRealTimers();
});
await waitFor(() => {
expect(getComponentNavigation).toHaveBeenCalledTimes(1);
});
- expect(getComponentNavigation).toHaveBeenCalledTimes(1);
- expect(getTasksForComponent).toHaveBeenCalledTimes(1);
+ await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1));
+
+ act(() => jest.runOnlyPendingTimers());
jest.runOnlyPendingTimers();
expect(getTasksForComponent).toHaveBeenCalledTimes(3);
// Make sure the timeout was cleared. It should not be called again.
- jest.runAllTimers();
+ act(() => jest.runAllTimers());
+
// The number of calls haven't changed.
await waitFor(() => {
expect(getComponentNavigation).toHaveBeenCalledTimes(2);
await waitFor(() => {
expect(getComponentNavigation).toHaveBeenCalledTimes(1);
});
- expect(getTasksForComponent).toHaveBeenCalledTimes(1);
+ await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1));
+
+ act(() => jest.runOnlyPendingTimers());
jest.runOnlyPendingTimers();
expect(getComponentNavigation).toHaveBeenCalledTimes(1);
});
- expect(getTasksForComponent).toHaveBeenCalledTimes(1);
+ await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1));
});
it('only fully reloads a non-empty component if there was previously some task in progress', async () => {
// First round, a pending task in the queue. This should trigger a reload of the
// status endpoint.
- await waitFor(() => {
- expect(getTasksForComponent).toHaveBeenCalledTimes(1);
- });
- jest.runOnlyPendingTimers();
+ await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1));
+
+ act(() => jest.runOnlyPendingTimers());
// Second round, nothing in the queue, and a success task is current. This
// implies the current task was updated, and previously we displayed some information
describe('issues app filtering', () => {
it('should combine sidebar filters properly', async () => {
jest.useFakeTimers();
- const user = userEvent.setup({ delay: null });
+ const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });
renderIssueApp();
await waitOnDataLoaded();
expect(ui.issueItem5.get()).toBeInTheDocument();
expect(ui.issueItem6.get()).toBeInTheDocument();
expect(ui.issueItem7.get()).toBeInTheDocument();
+ jest.runOnlyPendingTimers();
jest.useRealTimers();
});
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { screen } from '@testing-library/react';
+import { act, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import * as React from 'react';
import { renderComponent } from '../../../helpers/testReactTestingUtils';
});
it('should allow its content to be copied', async () => {
- const user = userEvent.setup();
+ const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });
renderClipboardBase();
user.click(screen.getByRole('button'));
expect(await screen.findByText('copied')).toBeInTheDocument();
- jest.runAllTimers();
+ act(() => jest.runAllTimers());
expect(screen.getByText('click to copy')).toBeInTheDocument();
});