All files / src index.js

100% Statements 22/22
100% Branches 16/16
100% Functions 9/9
100% Lines 22/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                22x 22x 22x   22x 3x 3x     22x 1x 1x     22x 1x     22x               22x   220x 220x         22x 1x 1x 2x 1x 1x           3x        
import { createLocalVue, mount, Wrapper } from '@vue/test-utils'
import Vuex from 'vuex'
import VueRouter from 'vue-router'
import waitForExpect from 'wait-for-expect'
import Simulate from './Simulate'
import * as queries from './queries'
 
function render(TestComponent, { props = null, store = null, routes = null } = {}, configurationCb) {
  const localVue = createLocalVue()
  let vuexStore = null
  let router = null
 
  if (store) {
    localVue.use(Vuex)
    vuexStore = new Vuex.Store(store)
  }
 
  if (routes) {
    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
  })
 
  const wrapperHelpers = Object.entries(queries).reduce(
    (helpers, [key, fn]) => {
      helpers[key] = fn.bind(null, wrapper)
      return helpers
    },
    {},
  )
 
  return {
    unmount: () => wrapper.destroy(),
    isUnmounted: () => wrapper.vm._isDestroyed,
    html: () => wrapper.html(),
    updateProps: _ => wrapper.setProps(_),
    updateState: _ => wrapper.setData(_),
    ...wrapperHelpers
  }
}
 
function wait(callback = () => {}, {timeout = 4500, interval = 50} = {}) {
  return waitForExpect(callback, timeout, interval)
}
 
export { render, wait, Simulate }