All files index.js

94.74% Statements 36/38
92.86% Branches 13/14
92.31% Functions 12/13
94.74% Lines 36/38
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98                        9x             12x 12x 12x   12x 3x 3x 3x     12x 1x 1x 1x         12x 1x     12x                 12x   12x 1x 1x 1x 1x     1x 1x   1x           1x       1x     1x 1x     9x 621x 621x 11x 11x       9x 1x 1x                
import {
  createLocalVue,
  mount
} from '@vue/test-utils'
 
import {
  getQueriesForElement,
  prettyDOM,
  wait,
  fireEvent
} 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
  })
 
  mountedWrappers.add(wrapper)
 
  return {
    debug: () => console.log(prettyDOM(wrapper.element)),
    unmount: () => wrapper.destroy(),
    isUnmounted: () => wrapper.vm._isDestroyed,
    html: () => wrapper.html(),
    emitted: () => wrapper.emitted(),
    updateProps: _ => {
      wrapper.setProps(_)
      return wait()
    },
    updateState: _ => wrapper.setData(_),
    ...getQueriesForElement(wrapper.element)
  }
}
 
function cleanup () {
  mountedWrappers.forEach(cleanupAtWrapper)
}
 
function cleanupAtWrapper (wrapper) {
  Iif (wrapper.parentNode === document.body) {
    document.body.removeChild(wrapper)
  }
  wrapper.destroy()
  mountedWrappers.delete(wrapper)
}
 
Object.keys(fireEvent).forEach(fn => {
  fireEvent[`_${fn}`] = fireEvent[fn]
  fireEvent[fn] = async (...params) => {
    fireEvent[`_${fn}`](...params)
    await wait()
  }
})
 
fireEvent.touch = async (elem) => {
  await fireEvent.focus(elem)
  await fireEvent.blur(elem)
}
 
export * from 'dom-testing-library'
export {
  cleanup,
  render
}