mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-05 23:46:28 +08:00
test: change to fakeTimer when error happens sometimes (#36102)
This commit is contained in:
parent
63fc5055f9
commit
96ccdfedf1
@ -1,6 +1,7 @@
|
||||
import React from 'react';
|
||||
import { LikeOutlined, SmileOutlined } from '@ant-design/icons';
|
||||
import * as copyObj from 'copy-to-clipboard';
|
||||
import { act } from '@testing-library/react';
|
||||
import { fireEvent, render, waitFor } from '../../../tests/utils';
|
||||
|
||||
import Base from '../Base';
|
||||
@ -233,7 +234,8 @@ describe('Typography copy', () => {
|
||||
fireEvent.click(wrapper.querySelectorAll('.ant-typography-copy')[0]);
|
||||
});
|
||||
|
||||
it('copy to clipboard', done => {
|
||||
it('copy to clipboard', () => {
|
||||
jest.useFakeTimers();
|
||||
const spy = jest.spyOn(copyObj, 'default');
|
||||
const originText = 'origin text.';
|
||||
const nextText = 'next text.';
|
||||
@ -243,7 +245,7 @@ describe('Typography copy', () => {
|
||||
setTimeout(() => {
|
||||
setDynamicText(nextText);
|
||||
}, 500);
|
||||
});
|
||||
}, []);
|
||||
return (
|
||||
<Base component="p" copyable>
|
||||
{dynamicText}
|
||||
@ -254,12 +256,13 @@ describe('Typography copy', () => {
|
||||
const copyBtn = wrapper.querySelectorAll('.ant-typography-copy')[0];
|
||||
fireEvent.click(copyBtn);
|
||||
expect(spy.mock.calls[0][0]).toEqual(originText);
|
||||
setTimeout(() => {
|
||||
spy.mockReset();
|
||||
fireEvent.click(copyBtn);
|
||||
expect(spy.mock.calls[0][0]).toEqual(nextText);
|
||||
done();
|
||||
}, 500);
|
||||
act(() => {
|
||||
jest.runAllTimers();
|
||||
});
|
||||
spy.mockReset();
|
||||
fireEvent.click(copyBtn);
|
||||
expect(spy.mock.calls[0][0]).toEqual(nextText);
|
||||
jest.useRealTimers();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user