Browse Source

test: improve test cases for Statistic (#36034)

pull/36084/head
Yuki Zhang 2 years ago
committed by GitHub
parent
commit
88858c7888
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      components/statistic/__tests__/index.test.tsx

28
components/statistic/__tests__/index.test.tsx

@ -100,19 +100,13 @@ describe('Statistic', () => {
it('time going', async () => {
const now = Date.now() + 1000;
const onFinish = jest.fn();
let instance: Countdown | null;
const instance = React.createRef<Countdown>();
const { unmount } = render(
<Statistic.Countdown
ref={n => {
instance = n;
}}
value={now}
onFinish={onFinish}
/>,
<Statistic.Countdown ref={instance} value={now} onFinish={onFinish} />,
);
// setInterval should work
expect(instance!.countdownId).not.toBe(undefined);
expect(instance.current!.countdownId).not.toBe(undefined);
await sleep(10);
@ -162,19 +156,11 @@ describe('Statistic', () => {
describe('time finished', () => {
it('not call if time already passed', () => {
const now = Date.now() - 1000;
let instance: Countdown | null;
const instance = React.createRef<Countdown>();
const onFinish = jest.fn();
render(
<Statistic.Countdown
ref={n => {
instance = n;
}}
value={now}
onFinish={onFinish}
/>,
);
expect(instance!.countdownId).toBe(undefined);
render(<Statistic.Countdown ref={instance} value={now} onFinish={onFinish} />);
expect(instance.current!.countdownId).toBe(undefined);
expect(onFinish).not.toHaveBeenCalled();
});

Loading…
Cancel
Save