2018-01-21 01:03:51 +08:00
|
|
|
import MockDate from 'mockdate';
|
2020-09-20 21:13:43 +08:00
|
|
|
import { act } from 'react-dom/test-utils';
|
2018-01-21 01:03:51 +08:00
|
|
|
|
2018-03-12 11:01:49 +08:00
|
|
|
export function setMockDate(dateString = '2017-09-18T03:30:07.795') {
|
2020-05-21 23:27:02 +08:00
|
|
|
MockDate.set(dateString);
|
2018-01-21 01:03:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function resetMockDate() {
|
|
|
|
MockDate.reset();
|
|
|
|
}
|
2019-07-24 22:56:20 +08:00
|
|
|
|
2020-06-09 18:10:43 +08:00
|
|
|
const globalTimeout = global.setTimeout;
|
|
|
|
|
2020-09-20 21:13:43 +08:00
|
|
|
export const sleep = async (timeout = 0) => {
|
|
|
|
await act(async () => {
|
2021-11-26 15:19:31 +08:00
|
|
|
await new Promise(resolve => {
|
|
|
|
globalTimeout(resolve, timeout);
|
|
|
|
});
|
2020-09-20 21:13:43 +08:00
|
|
|
});
|
|
|
|
};
|