You’re browsing the documentation for Vue Test Utils for Vue v2.x and earlier.
To read docs for Vue Test Utils for Vue 3, click here.
find
Deprecation warning
Using find
to search for a Component is deprecated and will be removed. Use findComponent
instead.
The find
method will continue to work for finding elements using any valid selector.
Returns Wrapper
of first DOM node or Vue component matching selector.
Use any valid DOM selector (uses querySelector
syntax).
Arguments:
{string} selector
Returns:
{Wrapper}
Example:
import { mount } from '@vue/test-utils'
import Foo from './Foo.vue'
import Bar from './Bar.vue'
const wrapper = mount(Foo)
const div = wrapper.find('div')
expect(div.exists()).toBe(true)
const byId = wrapper.find('#bar')
expect(byId.element.id).toBe('bar')
Note:
- You may chain
find
calls together:
- You may chain
const button = wrapper.find({ ref: 'testButton' })
expect(button.find('.icon').exists()).toBe(true)
See also: get.