All files index.js

84.38% Statements 27/32
85.71% Branches 12/14
81.82% Functions 9/11
84.38% Lines 27/32
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                        9x             12x 12x 12x   12x 3x 3x 3x     12x 1x 1x 1x         12x 1x     12x                   12x 1x 1x 1x 1x     1x 1x   1x           1x                     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
  })
 
  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) {
  if (wrapper.parentNode === document.body) {
    document.body.removeChild(wrapper)
  }
  wrapper.destroy()
  mountedWrappers.delete(wrapper)
}
 
fireEvent.touch = (elem) => {
  fireEvent.focus(elem)
  fireEvent.blur(elem)
}
 
export * from 'dom-testing-library'
export {
  cleanup,
  render
}