fix: fix Alert findDOMNode error (#48868)

* fix: fix Alert findDOMNode error

* fix: update test
This commit is contained in:
Wanpan 2024-05-10 19:18:54 +08:00 committed by GitHub
parent c9f7f5d8e6
commit eb218e80c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 5 deletions

View File

@ -7,6 +7,7 @@ import ExclamationCircleFilled from '@ant-design/icons/ExclamationCircleFilled';
import InfoCircleFilled from '@ant-design/icons/InfoCircleFilled';
import classNames from 'classnames';
import CSSMotion from 'rc-motion';
import { composeRef } from 'rc-util/es/ref';
import pickAttrs from 'rc-util/lib/pickAttrs';
import type { ClosableType } from '../_util/hooks/useClosable';
@ -234,10 +235,10 @@ const Alert = React.forwardRef<AlertRef, AlertProps>((props, ref) => {
onLeaveStart={(node) => ({ maxHeight: node.offsetHeight })}
onLeaveEnd={afterClose}
>
{({ className: motionClassName, style: motionStyle }) => (
{({ className: motionClassName, style: motionStyle }, setRef) => (
<div
id={id}
ref={internalRef}
ref={composeRef(internalRef, setRef)}
data-show={!closed}
className={classNames(alertCls, motionClassName)}
style={{ ...alert?.style, ...style, ...motionStyle }}

View File

@ -26,6 +26,7 @@ describe('Alert', () => {
});
it('should show close button and could be closed', async () => {
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const onClose = jest.fn();
render(
<Alert
@ -36,13 +37,14 @@ describe('Alert', () => {
/>,
);
await userEvent.click(screen.getByRole('button', { name: /close/i }));
act(() => {
await act(async () => {
await userEvent.click(screen.getByRole('button', { name: /close/i }));
jest.runAllTimers();
});
expect(onClose).toHaveBeenCalledTimes(1);
expect(errSpy).not.toHaveBeenCalled();
errSpy.mockRestore();
});
it('custom action', () => {