Compare commits

...

2 Commits

Author SHA1 Message Date
inottn
2cc4ca63b5
test(FloatingBubble): reduce test run time (#12539) 2023-12-31 02:08:42 +08:00
inottn
329cfcd703
test(Toast): reduce test run time (#12538) 2023-12-31 02:07:55 +08:00
2 changed files with 24 additions and 17 deletions

View File

@ -171,8 +171,9 @@ test('should free direction move when axis is "xy" ', async () => {
});
test('should free direction move and magnetic to x axios when magnetic is "x" ', async () => {
const restore = mockGetBoundingClientRect({ width: 48, height: 48 });
vi.useFakeTimers();
const restore = mockGetBoundingClientRect({ width: 48, height: 48 });
const root = document.createElement('div');
mount(FloatingBubble, {
props: {
@ -187,8 +188,7 @@ test('should free direction move and magnetic to x axios when magnetic is "x" '
)!;
await triggerDrag(floatingBubbleEl, -100, -100);
await later(400);
await vi.advanceTimersByTimeAsync(400);
expect(floatingBubbleEl.style.transform).toEqual(
`translate3d(${window.innerWidth - 48 - 24}px, ${
@ -197,19 +197,20 @@ test('should free direction move and magnetic to x axios when magnetic is "x" '
);
await triggerDrag(floatingBubbleEl, -600, -100);
await later(400);
await vi.advanceTimersByTimeAsync(400);
expect(floatingBubbleEl.style.transform).toEqual(
`translate3d(${24}px, ${window.innerHeight - 48 - 24 - 200}px, 0)`,
);
restore();
vi.useRealTimers();
});
test('should offset control positioning when use v-model:offset ', async () => {
const restore = mockGetBoundingClientRect({ width: 48, height: 48 });
vi.useFakeTimers();
const restore = mockGetBoundingClientRect({ width: 48, height: 48 });
const root = document.createElement('div');
const wrapper = mount(FloatingBubble, {
props: {
@ -227,8 +228,7 @@ test('should offset control positioning when use v-model:offset ', async () => {
)!;
await triggerDrag(floatingBubbleEl, 100, 100);
await later(400);
await vi.advanceTimersByTimeAsync(400);
expect(floatingBubbleEl.style.transform).toEqual(
`translate3d(${300}px, ${300}px, 0)`,
@ -241,6 +241,7 @@ test('should offset control positioning when use v-model:offset ', async () => {
});
restore();
vi.useRealTimers();
});
test('should emit click when click wrapper', async () => {

View File

@ -10,15 +10,17 @@ import {
} from '../function-call';
test('toast disappeared after duration', async () => {
vi.useFakeTimers();
const onClose = vi.fn();
showToast({
duration: 10,
onClose,
});
expect(onClose).toHaveBeenCalledTimes(0);
await later(50);
expect(onClose).not.toHaveBeenCalled();
await vi.advanceTimersByTimeAsync(100);
expect(onClose).toHaveBeenCalledTimes(1);
vi.useRealTimers();
});
test('show loading toast', async () => {
@ -31,17 +33,19 @@ test('show loading toast', async () => {
});
test('show html toast', async () => {
vi.useFakeTimers();
showToast({
type: 'html',
className: 'html-toast',
message: '<div>Message</div>',
});
await vi.runAllTimersAsync();
await later(1000);
const toastText = document.querySelector(
'.html-toast .van-toast__text',
) as HTMLDivElement;
expect(toastText.innerHTML).toEqual('<div>Message</div>');
vi.useRealTimers();
});
test('icon prop', async () => {
@ -108,15 +112,15 @@ test('clear multiple toast', async () => {
});
test('remove toast DOM when cleared in multiple mode', async () => {
vi.useFakeTimers();
allowMultipleToast();
closeToast(true);
const toast = showToast({ className: 'remove-toast' });
await later();
await toast.close();
await later(100);
toast.close();
await vi.advanceTimersByTimeAsync(100);
expect(document.querySelector('.remove-toast')).toBeNull();
allowMultipleToast(false);
vi.useRealTimers();
});
test('set default options', async () => {
@ -151,13 +155,15 @@ test('set default options by type', async () => {
});
test('toast duration 0', async () => {
vi.useFakeTimers();
allowMultipleToast();
const onClose = vi.fn();
showToast({ duration: 0, onClose });
await later(2100);
expect(onClose).toHaveBeenCalledTimes(0);
await vi.advanceTimersByTimeAsync(100);
expect(onClose).not.toHaveBeenCalled();
allowMultipleToast(false);
vi.useRealTimers();
});
test('should trigger onClose callback after closed', async () => {