2020-09-27 12:10:36 +08:00
|
|
|
import { mount } from '@vue/test-utils'
|
|
|
|
import { merge } from 'lodash'
|
|
|
|
|
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?: () => {
|
|
|
|
[key: string]: any
|
|
|
|
}
|
|
|
|
methods?: {
|
|
|
|
[key: string]: (...args) => any
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
export const makeMountFunc = (defaultOptions) => {
|
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
|