From 424be118032f0ee267fff9a5152b94e140c02991 Mon Sep 17 00:00:00 2001 From: haochenguang <2293885211@qq.com> Date: Wed, 20 Mar 2024 20:20:49 +0800 Subject: [PATCH 1/2] feat: test-utils support vue2 --- packages/test-utils/src/utils.ts | 14 +++++++++++--- packages/test-utils/src/wrappers.ts | 19 +++++++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/packages/test-utils/src/utils.ts b/packages/test-utils/src/utils.ts index e1695875e8..1335578acc 100644 --- a/packages/test-utils/src/utils.ts +++ b/packages/test-utils/src/utils.ts @@ -1,8 +1,16 @@ +import { isVue3, nextTick } from 'vue-demi' + /** * A tick that users can use to work through the event queue */ export function tick(): Promise { - return new Promise(resolve => { - setTimeout(resolve, 0) - }) + return nextTick() +} + +export function resolveProps>(props: T) { + return isVue3 ? props : { props } +} + +export function resolveChildren(children: T) { + return isVue3 ? { default: () => children } : children } diff --git a/packages/test-utils/src/wrappers.ts b/packages/test-utils/src/wrappers.ts index 4a615e22ae..a499590764 100644 --- a/packages/test-utils/src/wrappers.ts +++ b/packages/test-utils/src/wrappers.ts @@ -7,6 +7,7 @@ import { import { HTML5Backend } from 'react-dnd-html5-backend' import { DndProvider } from 'vue3-dnd' import type { BackendFactory } from 'dnd-core' +import { resolveChildren, resolveProps } from './utils' /** * Wrap a Component with a DnDContext using the TestBackend @@ -36,7 +37,7 @@ export function wrapWithTestBackend( /** * Wrap a component with a DndContext providing a backend. * - * @param DecoratedComponent The compoent to decorate + * @param DecoratedComponent The component to decorate * @param Backend The backend to use (default=HTML5Backend) * @param backendOptions The optional backend options */ @@ -46,12 +47,18 @@ export function wrapWithBackend( backendOptions?: unknown ): Component { return defineComponent({ + inheritAttrs: false, render() { - // @ts-ignore - return h(DndProvider, { backend: Backend, options: backendOptions }, [ - // @ts-ignore - h(DecoratedComponent, { ...this.$attrs }), - ]) + return h( + DndProvider, + resolveProps({ + backend: Backend, + options: backendOptions, + }), + resolveChildren([ + h(DecoratedComponent, resolveProps({ ...this.$attrs })), + ]) + ) }, }) } From e955b1bfee3e05b995b462bd074d2a756c4848a4 Mon Sep 17 00:00:00 2001 From: haochenguang <2293885211@qq.com> Date: Wed, 20 Mar 2024 20:22:49 +0800 Subject: [PATCH 2/2] fix: test-utils tick use setTimeout --- packages/test-utils/src/utils.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/test-utils/src/utils.ts b/packages/test-utils/src/utils.ts index 1335578acc..9071de500d 100644 --- a/packages/test-utils/src/utils.ts +++ b/packages/test-utils/src/utils.ts @@ -1,10 +1,12 @@ -import { isVue3, nextTick } from 'vue-demi' +import { isVue3 } from 'vue-demi' /** * A tick that users can use to work through the event queue */ export function tick(): Promise { - return nextTick() + return new Promise(resolve => { + setTimeout(resolve, 0) + }) } export function resolveProps>(props: T) {