element-plus/packages/test-utils/make-mount.ts
qiang f83761dd2a
style(eslint-config): add eslint rules to restrict the imports of lodash (#15773)
* style(eslint-config): add eslint rules to restrict the imports of lodash

* fix: lint error

* test(components): [infinite-scroll] test error

* test(components): [infinite-scroll] test error
2024-02-03 12:10:23 +08:00

30 lines
648 B
TypeScript

import { mount } from '@vue/test-utils'
import { merge } from 'lodash-unified'
const makeMount = <C, O, E>(element: C, defaultOptions: O) => {
return (props: (E | O) | (E & O) = {} as E) =>
mount(element, merge({}, defaultOptions, props))
}
interface Options {
data?: () => {
[key: string]: unknown
}
methods?: {
[key: string]: (...args: unknown[]) => any
}
}
export const makeMountFunc = <T extends Record<string, unknown>>(
defaultOptions: T
) => {
return (template: string, options: Options) => {
return mount({
...merge({}, defaultOptions, options),
template,
})
}
}
export default makeMount