import Vue , { ComponentOptions } from 'vue' ; import { createLocalVue , mount as vueMount , MountOptions , shallowMount as vueShallowMount , ShallowMountOptions } from '@vue/test-utils' ; import VueCompositionAPI from '@src/api' ; const localVue = createLocalVue ( ) ; localVue . use ( VueCompositionAPI ) ; export const mount = ( Component , options ? ) => vueMount ( localVue . extend ( Component ) , options ) ; export const shallowMount = ( Component , options ? ) => vueShallowMount ( localVue . extend ( Component ) , options ) ; export const checkOnMountAndUnmountEvents = async ( target , events , testComponent ) => { const addEventListenerSpy = jest . spyOn ( target , 'addEventListener' ) ; const removeEventListenerSpy = jest . spyOn ( target , 'removeEventListener' ) ; const wrapper = mount ( testComponent ( ) ) ; await wrapper . vm . $nextTick ( ) ; expect ( addEventListenerSpy ) . toHaveBeenCalledTimes ( events . length ) ; events . forEach ( event => { expect ( addEventListenerSpy ) . toBeCalledWith ( event , expect . any ( Function ) ) ; } ) ; wrapper . destroy ( ) ; expect ( removeEventListenerSpy ) . toHaveBeenCalledTimes ( events . length ) ; events . forEach ( event => { expect ( removeEventListenerSpy ) . toBeCalledWith ( event , expect . any ( Function ) ) ; } ) ; } ; export const checkOnStartEvents = async ( target , events , testComponent ) => { const addEventListenerSpy = jest . spyOn ( target , 'addEventListener' ) ; const wrapper = mount ( testComponent ( ) ) ; expect ( addEventListenerSpy ) . toHaveBeenCalledTimes ( events . length ) ; wrapper . find ( '#stop' ) . trigger ( 'click' ) ; await wrapper . vm . $nextTick ( ) ; wrapper . find ( '#start' ) . trigger ( 'click' ) ; expect ( addEventListenerSpy ) . toHaveBeenCalledTimes ( events . length * 2 ) ; } ; export const checkOnStopEvents = async ( target , events , testComponent ) => { const removeEventListenerSpy = jest . spyOn ( target , 'removeEventListener' ) ; const wrapper = mount ( testComponent ( ) ) ; wrapper . find ( '#stop' ) . trigger ( 'click' ) ; await wrapper . vm . $nextTick ( ) ; expect ( removeEventListenerSpy ) . toHaveBeenCalledTimes ( events . length ) ; } ; export const checkElementExistenceOnMount = async ( mountType , testComponent , elementName = '#isTracking' ) => { const wrapper = mount ( testComponent ) ; await wrapper . vm . $nextTick ( ) ; expect ( wrapper . find ( elementName ) . exists ( ) ) . toBe ( mountType ) ; } ; export const flushPromises = ( ) => new Promise ( setImmediate ) ;