'Why is wrapper.findAllComponents not working?

This is the code I have:

  let routes = wrapper.findAllComponents('router-link')
  let route = wrapper.findComponent('router-link')

  console.log(routes.length) // 0
  console.log(route) // a useable component

I get a route with findComponent but findAllComponents returns to me an empty wrapperArray.



Solution 1:[1]

You need to set it into a global property. Check out the documentation here

import { shallowMount } from '@vue/test-utils'

shallowMount(Component, {
  global: {
      stubs: ['router-link', 'router-view']
  }
})

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 power-cut