Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/test-utils/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isVue3 } from 'vue-demi'

/**
* A tick that users can use to work through the event queue
*/
Expand All @@ -6,3 +8,11 @@ export function tick(): Promise<void> {
setTimeout(resolve, 0)
})
}

export function resolveProps<T extends Record<string, unknown>>(props: T) {
return isVue3 ? props : { props }
}

export function resolveChildren<T>(children: T) {
return isVue3 ? { default: () => children } : children
}
19 changes: 13 additions & 6 deletions packages/test-utils/src/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand All @@ -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 })),
])
)
},
})
}