import { mount } from '@src/helpers/test' ; import { computed } from '@src/api' ; import { useTimeout } from '@src/vue-use-kit' ; beforeEach ( ( ) => { jest . useFakeTimers ( ) ; } ) ; afterEach ( ( ) => { jest . clearAllTimers ( ) ; jest . clearAllMocks ( ) ; } ) ; const testComponent = ( ) => ( { template : `
    <div>
      <div id="isIdle" v-if="isIdle"></div>
      <div id="isReady" v-if="isReady"></div>
    </div>
  ` , setup ( ) { const { isReady } = useTimeout ( 1000 ) ; const isIdle = computed ( ( ) => isReady . value === null ) ; return { isReady , isIdle } ; } } ) ; describe ( 'useTimeout' , ( ) => { it ( 'should show #isReady when the timers are called, but not #isIdle' , async ( ) => { const wrapper = mount ( testComponent ( ) ) ; jest . runAllTimers ( ) ; await wrapper . vm . $nextTick ( ) ; expect ( wrapper . find ( '#isReady' ) . exists ( ) ) . toBe ( true ) ; expect ( wrapper . find ( '#isIdle' ) . exists ( ) ) . toBe ( false ) ; } ) ; } ) ;