title: how to mock module when using jest
body: <p>I'm using Jest for unit test in a vuejs2 project but got stuck in mocking <a href="https://howlerjs.com/" rel="nofollow noreferrer">howler.js</a>, a library imported in my component.  </p>
  
  <p>Suppose I have a component named <code>Player.vue</code></p>
  
  <pre><code>&lt;template&gt;
    &lt;div class="player"&gt;
      &lt;button class="player-button" @click="play"&gt;Player&lt;/button&gt;
    &lt;/div&gt;
  &lt;/template&gt;
  
  &lt;script&gt;
  import { Howl } from 'howler';
  
  export default {
    name: 'audioplayer',
    methods: {
      play() {
        console.log('player button clicked');
        new Howl({
          src: [ 'whatever.wav' ],
        }).play();
      }
    }
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>then I have its test file named <code>Player.spec.js</code>. Test code was written based on the answer <a href="https://stackoverflow.com/a/40465435/6279569">here</a>, but the test failed since <code>called</code> wasn't set as true. It seems that mocked constructor won't be called when running this test.  </p>
  
  <pre><code>import Player from './Player';
  import Vue from 'vue';
  
  describe('Player', () =&gt; {
    let called = false;
  
    jest.mock('howler', () =&gt; ({
      Howl({ src }) {
        this.play = () =&gt; {
          called = true;
          console.log(`playing ${src[0]} now`);
        };
      },
    }));
  
    test('should work', () =&gt; {
      const Constructor = Vue.extend(Player);
      const vm = new Constructor().$mount();
      vm.$el.querySelector('.player-button').click();
      expect(called).toBeTruthy(); // =&gt; will fail
    })
  })
  </code></pre>
  
  <p>Though I'm using Vuejs here, I considered it as a more general question related to the usage of Jest's <code>mock</code> API, but I'm not able to get further.</p>