All files index.js

85.71% Statements 24/28
85.71% Branches 12/14
88.89% Functions 8/9
85.71% Lines 24/28
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65        9x     12x 12x 12x   12x 3x 3x 3x     12x 1x 1x 1x     12x 1x     12x                 12x 1x 1x 1x 1x   1x 1x   1x           1x                          
import { createLocalVue, mount } from '@vue/test-utils'
import Simulate from './Simulate'
import { getQueriesForElement, prettyDOM, wait } from 'dom-testing-library'
 
const mountedWrappers = new Set()
 
function render (TestComponent, { props = null, store = null, routes = null } = {}, configurationCb) {
  const localVue = createLocalVue()
  let vuexStore = null
  let router = null
 
  if (store) {
    const Vuex = require('vuex')
    localVue.use(Vuex)
    vuexStore = new Vuex.Store(store)
  }
 
  if (routes) {
    const VueRouter = require('vue-router')
    localVue.use(VueRouter)
    router = new VueRouter(routes)
  }
 
  if (configurationCb && typeof configurationCb === 'function') {
    configurationCb(localVue)
  }
 
  const wrapper = mount(TestComponent, {
    localVue,
    router,
    store: vuexStore,
    propsData: { ...props },
    attachToDocument: true,
    sync: false
  })
 
  return {
    debug: () => console.log(prettyDOM(wrapper.element)),
    unmount: () => wrapper.destroy(),
    isUnmounted: () => wrapper.vm._isDestroyed,
    html: () => wrapper.html(),
    updateProps: _ => {
      wrapper.setProps(_)
      return wait()
    },
    updateState: _ => wrapper.setData(_),
    ...getQueriesForElement(wrapper.element)
  }
}
 
function cleanup () {
  mountedWrappers.forEach(cleanupAtWrapper)
}
 
function cleanupAtWrapper (wrapper) {
  if (wrapper.parentNode === document.body) {
    document.body.removeChild(wrapper)
  }
  wrapper.destroy()
  mountedWrappers.delete(wrapper)
}
 
export * from 'dom-testing-library'
export { cleanup, render, Simulate }