title: Async Jest test in vueJS lifecycle hook with Interval
body: <p>I would to understand how can i test my "auth/refresh" action in the "beforeCreate" hook with jest like below :</p>
  
  <p>// main.vue</p>
  
  <pre><code>async beforeCreate() {
      let authTokenRefreshIntervalId;
  
      await this.$store.dispatch('auth/initialize');
  
      authTokenRefreshIntervalId = setInterval(() =&gt; {
        this.$store.dispatch('auth/refresh').catch(() =&gt; {
          this.$store.dispatch('auth/logout');
          clearInterval(authTokenRefreshIntervalId);
        });
      }, 30 * 1000);
  }
  </code></pre>
  
  <p>// main.spec.js</p>
  
  <pre><code>import Vue from 'vue';
  import Vuex from 'vuex';
  import { shallow, createLocalVue, mount } from '@vue/test-utils';
  import Main from '@/main';
  
  const localVue = createLocalVue();
  
  jest.useFakeTimers();
  
  describe('store-auth', () =&gt; {
    let store;
    let actions;
    let getters;
  
    beforeEach(() =&gt; {
      actions = {
        initialize: jest.fn(),
        refresh: jest.fn(),
        logout: jest.fn(),
      };
  
      getters = {
        isAuthenticated: jest.fn(),
      };
  
      store = new Vuex.Store({
        modules: {
          auth: {
            namespaced: true,
            actions,
            getters,
          },
        },
      });
    });
  
    it('dispatch initialize on beforeCreate hook', () =&gt; {
      const wrapper = shallow(Main, { store, localVue });
      expect(actions.initialize).toHaveBeenCalled();
    });
  
    it('dispatch refresh on beforeCreate hook every 30s', () =&gt; {
      const wrapper = shallow(Main, { store, localVue });
      jest.runTimersToTime(30 * 1000);
      expect(actions.refresh).toHaveBeenCalled();
    });
  });
  </code></pre>
  
  <p>Jest say that the mocked function is not called.
  I tried with <code>expect(setInterval).toHaveBeenCalled()</code> and it pass the test.
  Where i'm wrong plz ?</p>