From 22fb6f67fa10e3cdc0e382c5e73869846e67de02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E7=88=B1=E5=90=83=E7=99=BD=E8=90=9D?= =?UTF-8?q?=E5=8D=9C?= Date: Thu, 12 Sep 2024 14:11:43 +0800 Subject: [PATCH] fix: invalid useApp warning (#50829) * fix: invalid warning * docs: back of demo --- components/_util/__tests__/useZIndex.test.tsx | 45 +++++++++++++++---- components/_util/hooks/useZIndex.ts | 9 +++- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/components/_util/__tests__/useZIndex.test.tsx b/components/_util/__tests__/useZIndex.test.tsx index e1ae21e112..977710ac19 100644 --- a/components/_util/__tests__/useZIndex.test.tsx +++ b/components/_util/__tests__/useZIndex.test.tsx @@ -1,8 +1,11 @@ import type { PropsWithChildren } from 'react'; import React, { useEffect } from 'react'; import { render } from '@testing-library/react'; -import type { ImageProps, MenuProps } from 'antd'; + +import { waitFakeTimer } from '../../../tests/utils'; +import type { ImageProps, MenuProps } from '../../index'; import { + App, AutoComplete, Cascader, ColorPicker, @@ -18,11 +21,10 @@ import { Tooltip, Tour, TreeSelect, -} from 'antd'; - -import { waitFakeTimer } from '../../../tests/utils'; +} from '../../index'; import type { ZIndexConsumer, ZIndexContainer } from '../hooks/useZIndex'; import { consumerBaseZIndexOffset, containerBaseZIndexOffset, useZIndex } from '../hooks/useZIndex'; +import { resetWarned } from '../warning'; import zIndexContext from '../zindexContext'; const WrapWithProvider: React.FC> = ({ @@ -229,6 +231,7 @@ function getConsumerSelector(baseSelector: string, consumer: ZIndexConsumer): st describe('Test useZIndex hooks', () => { beforeEach(() => { + resetWarned(); jest.useFakeTimers(); }); afterEach(() => { @@ -250,7 +253,7 @@ describe('Test useZIndex hooks', () => { return
Child
; }; - const App = () => ( + const Demo = () => ( @@ -259,7 +262,7 @@ describe('Test useZIndex hooks', () => { ); - render(); + render(); expect(fn).toHaveBeenLastCalledWith( 1000 + containerBaseZIndexOffset[containerKey as ZIndexContainer] * 3 + @@ -271,7 +274,7 @@ describe('Test useZIndex hooks', () => { const Container = containerComponent[containerKey as ZIndexContainer]; const Consumer = consumerComponent[key as ZIndexConsumer]; - const App = () => ( + const Demo = () => ( <> @@ -283,7 +286,7 @@ describe('Test useZIndex hooks', () => { ); - const { unmount } = render(); + const { unmount } = render(); await waitFakeTimer(1000); @@ -409,5 +412,31 @@ describe('Test useZIndex hooks', () => { expect(errorSpy).toHaveBeenCalledWith( 'Warning: [antd: Tooltip] `zIndex` is over design token `zIndexPopupBase` too much. It may cause unexpected override.', ); + + errorSpy.mockRestore(); + }); + + it('not warning for static func', () => { + const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + + const Demo = () => { + const { modal } = App.useApp(); + + React.useEffect(() => { + modal.confirm({ content: