2020-09-27 12:10:36 +08:00
|
|
|
import { mount } from '@vue/test-utils'
|
2024-02-03 12:10:23 +08:00
|
|
|
import { merge } from 'lodash-unified'
|
2020-09-27 12:10:36 +08:00
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
const makeMount = <C, O, E>(element: C, defaultOptions: O) => {
|
|
|
|
return (props: (E | O) | (E & O) = {} as E) =>
|
|
|
|
mount(element, merge({}, defaultOptions, props))
|
2020-09-27 12:10:36 +08:00
|
|
|
}
|
|
|
|
|
2021-07-23 17:06:01 +08:00
|
|
|
interface Options {
|
|
|
|
data?: () => {
|
2022-07-16 21:01:48 +08:00
|
|
|
[key: string]: unknown
|
2021-07-23 17:06:01 +08:00
|
|
|
}
|
|
|
|
methods?: {
|
2022-07-16 21:01:48 +08:00
|
|
|
[key: string]: (...args: unknown[]) => any
|
2021-07-23 17:06:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-16 21:01:48 +08:00
|
|
|
export const makeMountFunc = <T extends Record<string, unknown>>(
|
|
|
|
defaultOptions: T
|
|
|
|
) => {
|
2021-07-23 17:06:01 +08:00
|
|
|
return (template: string, options: Options) => {
|
|
|
|
return mount({
|
|
|
|
...merge({}, defaultOptions, options),
|
|
|
|
template,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-27 12:10:36 +08:00
|
|
|
export default makeMount
|