title: How to test a Vuex module action is called in Vue component mounted function?
body: <p>I have a Vue component like this...</p>
  <pre class="lang-html prettyprint-override"><code>&lt;template&gt;
    &lt;div class=&quot;mapdiv&quot;&gt;&lt;/div&gt;
  &lt;/template&gt;
  
  &lt;script lang=&quot;ts&quot;&gt;
  import Vue from &quot;vue&quot;;
  import Component from &quot;vue-class-component&quot;;
  import { mapViewModule } from &quot;@/store/modules/MapViewModule&quot;;
  
  @Component
  export default class GeospatialMap extends Vue {
    async mounted(): Promise&lt;void&gt; {
      mapViewModule.initializeMapView(this.$el as HTMLDivElement);
    }
  }
  &lt;/script&gt;
  
  &lt;style scoped&gt;
  .mapdiv {
    height: 700px;
    width: 1000px;
  }
  &lt;/style&gt;
  </code></pre>
  <p>...and I am trying to test that  the <code>mapViewModule.initalizeMapView</code> function gets called, which is an action in my Vuex module.</p>
  <p>I am using Jest and have looked to other answers such as: <a href="https://stackoverflow.com/a/66987942/2052752">https://stackoverflow.com/a/66987942/2052752</a> but have had no luck....</p>
  <pre class="lang-js prettyprint-override"><code>import { shallowMount, createLocalVue } from &quot;@vue/test-utils&quot;;
  import Vuex from &quot;vuex&quot;;
  import GeospatialMap from &quot;@/components/Geospatial.vue&quot;;
  
  describe(&quot;GeospatialMap - &quot;, () =&gt; {
    const localVue = createLocalVue();
    localVue.use(Vuex);
    const modules = {
      mapViewModule: {
        state: {},
        actions: {
          initializeMapView: jest.fn()
        },
        namespaced: true
      }
    };
    const store = new Vuex.Store({ modules });
  
    shallowMount(GeospatialMap, { localVue, store });
  
    it(&quot;when component created, initializes the map view&quot;, async () =&gt; {
      expect(modules.mapViewModule.actions.initializeMapView).toHaveBeenCalled();
    });
  });
  </code></pre>
  <p>Simply put...the jest.fn says its not called in the console..</p>
  <pre><code>expect(jest.fn()).toHaveBeenCalled()
  
      Expected number of calls: &gt;= 1
      Received number of calls:    0
  </code></pre>
  <p>I'm not sure where it is going wrong. Am I not mocking the module action right?</p>
  <p>I just want to test that the Vuex action gets called when this component is initialized.</p>