2019-01-12 03:33:27 +00:00
|
|
|
import moment from 'moment';
|
|
|
|
import MockDate from 'mockdate';
|
2020-06-11 07:58:41 +00:00
|
|
|
import { nextTick } from 'vue';
|
2018-05-13 15:11:51 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
export function setMockDate(dateString = '2017-09-18T03:30:07.795') {
|
|
|
|
MockDate.set(moment(dateString));
|
2018-05-13 15:11:51 +00:00
|
|
|
}
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
export function resetMockDate() {
|
|
|
|
MockDate.reset();
|
2018-05-13 15:11:51 +00:00
|
|
|
}
|
2018-06-06 02:48:15 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
export function asyncExpect(fn, timeout) {
|
|
|
|
return new Promise(resolve => {
|
2018-06-06 02:48:15 +00:00
|
|
|
if (typeof timeout === 'number') {
|
|
|
|
setTimeout(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
fn();
|
|
|
|
resolve();
|
|
|
|
}, timeout);
|
2018-06-06 02:48:15 +00:00
|
|
|
} else {
|
2020-06-11 07:58:41 +00:00
|
|
|
nextTick(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
fn();
|
|
|
|
resolve();
|
|
|
|
});
|
2018-06-06 02:48:15 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-06-06 02:48:15 +00:00
|
|
|
}
|
2020-03-07 11:45:13 +00:00
|
|
|
export const sleep = (timeout = 0) => new Promise(resolve => setTimeout(resolve, timeout));
|