make-mount.ts 640 B

1234567891011121314151617181920212223242526272829
  1. import { mount } from '@vue/test-utils'
  2. import { merge } from 'lodash'
  3. const makeMount = <C, O, E>(element: C, defaultOptions: O) => {
  4. return (props: (E | O) | (E & O) = {} as E) =>
  5. mount(element, merge({}, defaultOptions, props))
  6. }
  7. interface Options {
  8. data?: () => {
  9. [key: string]: unknown
  10. }
  11. methods?: {
  12. [key: string]: (...args: unknown[]) => any
  13. }
  14. }
  15. export const makeMountFunc = <T extends Record<string, unknown>>(
  16. defaultOptions: T
  17. ) => {
  18. return (template: string, options: Options) => {
  19. return mount({
  20. ...merge({}, defaultOptions, options),
  21. template,
  22. })
  23. }
  24. }
  25. export default makeMount