Jest Global Plugin in Nuxt.js

Viewed 1123

I am trying to mock out a plugin that runs on the created() hook inside a jest unit test, however, I keep getting back TypeError: this.$translations is not a function which is causing all my tests to fail with that error:

Inside the Component file:

created () {
  this.$translations(this.page.translations)
}

Inside the Test file:

import { translations } from '~/helpers/plugins/translations'

const localVue = createLocalVue()
localVue.use(translations)

const wrapper = shallowMount(TestComponent, {
  localVue,
  propsData
})

Am I doing something wrong?

1 Answers

I have solved this, what i had to do was use mocks to mock the this.$translations() as a function:

const wrapper = shallowMount(TBase, {
  localVue,
  mocks: { $translations: () => {} },
  propsData
})
Related