From d1ca3a9797bce9e8677051ecd73bb34a4f4969aa Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Tue, 21 Feb 2023 12:51:01 +0100 Subject: [PATCH] fix false positive log when running tests Let's wrap the test in `act` to get rid of the warning. In practice (while testing in the browser) the actual warning doesn't seem to affect the user experience at all. The `act` function is typed in a strange way (`Promise & void`). Yet the actual contents of the `act` callback is returned as expected. Therefore we overrode the type of `act` to make sure this reflects reality better. (Thanks @thecrypticace!) Also added an additional check to make sure the actual `container` is available to extra ensure we are not lying by overriding the type. --- .../transitions/transition.test.tsx | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/packages/@headlessui-react/src/components/transitions/transition.test.tsx b/packages/@headlessui-react/src/components/transitions/transition.test.tsx index aa384d2ba4..471fca4060 100644 --- a/packages/@headlessui-react/src/components/transitions/transition.test.tsx +++ b/packages/@headlessui-react/src/components/transitions/transition.test.tsx @@ -1,11 +1,13 @@ import React, { Fragment, useState, useRef, useLayoutEffect, useEffect } from 'react' -import { render, fireEvent } from '@testing-library/react' +import { render, fireEvent, act as _act } from '@testing-library/react' import { suppressConsoleLogs } from '../../test-utils/suppress-console-logs' import { Transition } from './transition' import { executeTimeline } from '../../test-utils/execute-timeline' +let act = _act as unknown as (fn: () => T) => PromiseLike + function nextFrame() { return new Promise((resolve) => { requestAnimationFrame(() => { @@ -423,22 +425,26 @@ describe('Setup API', () => { `) }) - it('should be possible to passthrough the transition classes and immediately apply the enter transitions when appear is set to true', () => { - let { container } = render( - - Children - + it('should be possible to passthrough the transition classes and immediately apply the enter transitions when appear is set to true', async () => { + let { container } = await act(() => + render( + + Children + + ) ) + expect(container).toBeDefined() + expect(container.firstChild).toMatchInlineSnapshot(`