Skip to content

Latest commit

 

History

History
59 lines (41 loc) · 1.3 KB

createLocalVue.md

File metadata and controls

59 lines (41 loc) · 1.3 KB

createLocalVue()

  • Arguments:

    • {Object} options
      • {Function} errorHandler
  • Returns:

    • {Component}
  • Usage:

createLocalVue returns a Vue class for you to add components, mixins and install plugins without polluting the global Vue class.

The errorHandler option can be used to handle uncaught errors during component render function and watchers.

Use it with options.localVue:

Without options:

import { createLocalVue, shallowMount } from '@vue/test-utils'
import MyPlugin from 'my-plugin'
import Foo from './Foo.vue'

const localVue = createLocalVue()
localVue.use(MyPlugin)
const wrapper = shallowMount(Foo, {
  localVue,
  mocks: { foo: true }
})
expect(wrapper.vm.foo).toBe(true)

const freshWrapper = shallowMount(Foo)
expect(freshWrapper.vm.foo).toBe(false)

With the errorHandler option:

import { createLocalVue, shallowMount } from '@vue/test-utils'
import Foo from './Foo.vue'

const errorHandler = (err, vm, info) => {
  expect(err).toBeInstanceOf(Error)
}

const localVue = createLocalVue({
  errorHandler
})

// Foo throws an error inside a lifecycle hook
const wrapper = shallowMount(Foo, {
  localVue
})