{
expect(externalLink.getAttribute('href')).toEqual('https://external.com');
});
- test('internal click behaviour', () => {
+ test('internal click behaviour', async () => {
+ const user = userEvent.setup();
// check that default behaviour wasn't prevented by wrapping in a div
// where we have access to the onClick method
// https://github.com/testing-library/react-testing-library/issues/572#issuecomment-574804033
@@ -41,7 +42,7 @@ describe('Link', () => {
const pushStateSpy = jest.spyOn(window.history, 'pushState');
- userEvent.click(link.getByText('Clickable'));
+ await user.click(link.getByText('Clickable'));
// default behaviour prevented
expect(outerOnClick.mock.calls).toHaveLength(1);
@@ -65,7 +66,8 @@ describe('Link', () => {
expect(pushStateSpy.mock.calls[0]).toEqual([{}, '', '/internal']);
});
- test('external click behaviour', () => {
+ test('external click behaviour', async () => {
+ const user = userEvent.setup();
const outerOnClick = jest.fn();
const link = render(
outerOnClick(e.defaultPrevented)}>
@@ -73,14 +75,15 @@ describe('Link', () => {
);
- userEvent.click(link.getByText('Clickable'));
+ await user.click(link.getByText('Clickable'));
// default link behaviour not prevented
expect(outerOnClick.mock.calls).toHaveLength(1);
expect(outerOnClick.mock.calls[0][0]).toBe(false);
});
- test('"external_link" prop creates external link', () => {
+ test('"external_link" prop creates external link', async () => {
+ const user = userEvent.setup();
const outerOnClick = jest.fn();
const link = render(
outerOnClick(e.defaultPrevented)}>
@@ -90,7 +93,7 @@ describe('Link', () => {
);
- userEvent.click(link.getByText('Clickable'));
+ await user.click(link.getByText('Clickable'));
// default link behaviour not prevented
expect(outerOnClick.mock.calls).toHaveLength(1);
@@ -104,7 +107,8 @@ describe('Link', () => {
outerOnClick = jest.fn();
});
- test('internal', () => {
+ test('internal', async () => {
+ const user = userEvent.setup();
const link = render(
outerOnClick(e.defaultPrevented)}>
@@ -118,7 +122,7 @@ describe('Link', () => {
window.dispatchEvent = mockDispatchEvent;
window.scrollTo = mockScrollTo;
- userEvent.click(link.getByText('Clickable'));
+ await user.click(link.getByText('Clickable'));
expect(outerOnClick.mock.calls).toHaveLength(1);
expect(outerOnClick.mock.calls[0][0]).toBe(true);
@@ -127,7 +131,8 @@ describe('Link', () => {
expect(mockScrollTo.mock.calls).toHaveLength(0);
});
- test('external', () => {
+ test('external', async () => {
+ const user = userEvent.setup();
const link = render(
outerOnClick(e.defaultPrevented)}>
@@ -136,7 +141,7 @@ describe('Link', () => {
);
- userEvent.click(link.getByText('Clickable'));
+ await user.click(link.getByText('Clickable'));
expect(outerOnClick.mock.calls).toHaveLength(1);
expect(outerOnClick.mock.calls[0][0]).toBe(true);
diff --git a/src/private/__tests__/Overlay.test.js b/src/private/__tests__/Overlay.test.js
index 59a00626f..ad355c210 100644
--- a/src/private/__tests__/Overlay.test.js
+++ b/src/private/__tests__/Overlay.test.js
@@ -3,8 +3,9 @@
*/
import React from 'react';
-import {render} from '@testing-library/react';
+import {act, render} from '@testing-library/react';
import Overlay from '../Overlay';
+
jest.useFakeTimers();
const CustomChild = React.forwardRef((props, ref) => (
@@ -14,53 +15,41 @@ const CustomChild = React.forwardRef((props, ref) => (
));
describe('Overlay with dict id', () => {
- // this is just a little hack to silence a warning that we'll get until we
- // upgrade to 16.9. See also: https://github.com/facebook/react/pull/14853
- const originalError = console.error;
- beforeAll(() => {
- console.error = (...args) => {
- if (/Warning.*not wrapped in act/.test(args[0])) {
- return;
- }
- originalError.call(console, ...args);
- };
- });
-
- afterAll(() => {
- console.error = originalError;
- });
-
let div;
beforeAll(() => {
div = document.createElement('div');
div.setAttribute('id', '{"index":1,"type":"target"}');
});
- test('renders nothing by default', () => {
- render(
-
-
- ,
- {
- container: document.body.appendChild(div)
- }
+ test('renders nothing by default', async () => {
+ await act(async () =>
+ render(
+
+
+ ,
+ {
+ container: document.body.appendChild(div)
+ }
+ )
);
+ await act(async () => jest.runAllTimers());
expect(document.body.querySelector('#content')).toBe(null);
});
- test('renders its content', () => {
- render(
-
-
- ,
- {
- container: document.body.appendChild(div)
- }
+ test('renders its content', async () => {
+ await act(async () =>
+ render(
+
+
+ ,
+ {
+ container: document.body.appendChild(div)
+ }
+ )
);
- jest.runAllTimers();
-
+ await act(async () => jest.runAllTimers());
expect(document.body.querySelector('#content')).not.toBe(null);
});
});