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: