title: How to implement unit testing for a global resposeBus which emits functions in vue
body: <p>I want to implement unit testing using vue-test utils for a vue component which uses a global event handler as a vue instance called responseBus. Need to implement unit test using jest.</p>
  <p>Here is the code for vue component.</p>
  <pre><code>    &lt;script&gt;
  import NewQuestionBuilder from '@/components/NewQuestionBuilder.vue'
  
  export default {
    inject: ['$responseBus'],
    props: {
      question: {
        type: Object,
        required: true,
      },
    },
    mounted() {
      this.$responseBus.$on('pseudo', (payload) =&gt; {
        if (payload.questionCode === this.question.questionCode) {
          this.$emit('update:initialValue', payload)
        }
      })
    },
    render(h) {
      return h('div', { class: 'pl-0 md:pl-4 w-full ' }, [
        h(NewQuestionBuilder, { props: { questionData: this.question } }),
      ])
    },
  }
  &lt;/script&gt;
  </code></pre>
  <p>Here is the unit test file.</p>
  <pre><code>    import { shallowMount, createLocalVue } from '@vue/test-utils'
  import Vue from 'vue'
  import Component from '../BaseComputed'
  
  const GlobalPlugins = {
    install(v) {
      v.prototype.$eventBus = new Vue()
    },
  }
  
  const localVue = createLocalVue()
  localVue.use(GlobalPlugins)
  
  describe('BaseComputed', () =&gt; {
    const mocks = {
      $responseBus: {
        $on: jest.fn(),
        $off: jest.fn(),
        $emit: jest.fn(),
      },
    }
  
    it('listens to event pseudo', () =&gt; {
      const wrapper = shallowMount(Component, {
        mocks,
        propsData: {
          imageUrl: '',
          label: ``,
          initialValue: [],
          isEnabled: true,
          code: '',
          triggers: [],
          choices: [],
          question: {
            questionCode: 'HFFIN0416USOTEL',
          },
        },
      })
      wrapper.vm.$responseBus.$emit('pseudo', {
        questionCode: `HFFIN0416USOTEL`,
      })
      expect(wrapper.vm.question.questionCode).toEqual('HFFIN0416USOTEL')
      expect(wrapper.vm.$responseBus.$on).toHaveBeenCalledTimes(1)
      expect(wrapper.vm.$responseBus.$on).toHaveBeenCalledWith(
        'pseudo',
        jest.fn((payload) =&gt; {
          if (payload.questionCode === this.question.questionCode) {
            this.$emit('update:initialValue', payload)
          }
        })
      )
  })
  })
  </code></pre>
  <p>Still couldn't test the 'psuedo' method. Guys need help to achieve this.</p>