Search code examples
vue.jsjestjsvue-test-utils

Vue Test Utils with Jest - Mixins not working


I have created a local Vue app and I need to mix a method into all components. The problem is whenever I mount the app the method does not appear to be mixed for child components. Here is my code:

import { createLocalVue, mount } from '@vue/test-utils'
import {gc} from '.....';
import .... from ....

const App = createLocalVue()

App.use( .... )

App.mixin({
  methods: {
    gc: key => gc(key)
  }
})

export const Wrapper = mount(AppComponent, {
  App,
  i18n,
  router,
  store,
  ...
})

Whenever I import "Wrapper" into any test it fails to the first mounted component with message:

TypeError: _vm.gc is not a function

How can I include mixins to propagate to all the child components?


Solution

  • mount has no App option. Instead, there's localVue to supply Vue copy.

    It should be:

     mount(AppComponent, {
      localVue: App,
      ...