Skip to content

Commit

Permalink
fix: fix Badge CSSMotion setref use error and add test case (#48878)
Browse files Browse the repository at this point in the history
  • Loading branch information
wanpan11 committed May 11, 2024
1 parent c656603 commit 470e8a8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
38 changes: 25 additions & 13 deletions components/badge/__tests__/index.test.tsx
@@ -1,9 +1,9 @@
import React from 'react';
import { act, fireEvent, render } from '@testing-library/react';

import type { GetRef } from '../../_util/type';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { act, fireEvent, render, waitFakeTimer } from '../../../tests/utils';
import Tooltip from '../../tooltip';
import Badge from '../index';

Expand All @@ -26,19 +26,31 @@ describe('Badge', () => {
jest.useRealTimers();
});

it('no strict warning', () => {
it('no strict warning', async () => {
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const { rerender } = render(
<Badge dot>
<span />
</Badge>,
);

rerender(
<Badge>
<span />
</Badge>,
);
const Comp = () => {
const [count, setCount] = React.useState<number | null>(9999);

return (
<>
<Badge count={count}>
<span>Badge</span>
</Badge>

<br />
<br />
<br />

<button type="button" onClick={() => setCount(null)}>
click
</button>
</>
);
};
const { container } = render(<Comp />);

fireEvent.click(container.querySelector('button')!);
await waitFakeTimer();

expect(errSpy).not.toHaveBeenCalled();
errSpy.mockRestore();
Expand Down
3 changes: 1 addition & 2 deletions components/badge/index.tsx
Expand Up @@ -216,7 +216,7 @@ const InternalBadge = React.forwardRef<HTMLSpanElement, BadgeProps>((props, ref)
motionAppear={false}
motionDeadline={1000}
>
{({ className: motionClassName, ref: scrollNumberRef }) => {
{({ className: motionClassName }) => {
const scrollNumberPrefixCls = getPrefixCls(
'scroll-number',
customizeScrollNumberPrefixCls,
Expand Down Expand Up @@ -255,7 +255,6 @@ const InternalBadge = React.forwardRef<HTMLSpanElement, BadgeProps>((props, ref)
title={titleNode}
style={scrollNumberStyle}
key="scrollNumber"
ref={scrollNumberRef}
>
{displayNode}
</ScrollNumber>
Expand Down

0 comments on commit 470e8a8

Please sign in to comment.