composition-api icon indicating copy to clipboard operation
composition-api copied to clipboard

help: Plugins Inject Unit Test

Open ariefsn opened this issue 4 years ago • 1 comments

📚 What are you trying to do? Please describe. Hi, how to mock injection? injection was working fine, but its become undefined when running test. Nuxt2 + Typescript + CompositionApi

// plugins/myPlugin.ts
const utility: Plugin = (context, inject) => {
  inject('myFunc', (str: string) => str)
}

export default utility
// components/MyComponent.vue
setup() {
   const { $myFunc } = useContext()

   onMounted(() => {
      console.log('myFunc', $myfunc) // will print undefined on testing
   })
}
// test/MyComponent.spec.ts
const wrapper = mount(MyComponent, {
   localVue,
   mocks: {
      $myFunc: (str: string) => str
   }
})

🔍 What have you tried? Have mocks in options, still not works.

ℹ️ Additional context

ariefsn avatar Nov 04 '21 08:11 ariefsn