Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update selectors.md
Added a component example, with a template, to make it clear how the selectors can work
  • Loading branch information
skillsnate authored Jan 1, 2024
commit ca5a68bce16353fed7ed3cd38f76a67f47fa7ffc
31 changes: 30 additions & 1 deletion docs/api/selectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,35 @@ expect(wrapper.is(Foo)).toBe(true)

### Find Option Object

Suppose you have the following component
```js
// MyButtonComponent.vue

<template>
<button class="btn" name="my-button" :ref="myButtonRef">Click My Button</button>
</template>
<script lang="ts">
export default defineComponent({
name: 'MyButtonComponent',
computed: {
myButtonRef() {
return 'dynamic-my-button-ref';
}
}
</script>

or

const MyButtonComponent = {
template: '<button class="btn" name="my-button" :ref="myButtonRef">Click My Button</button>',
computed: {
myButtonRef() {
return 'dynamic-my-button-ref';
}
}
};
```

#### Name

Using a find option object, Vue Test Utils allows for selecting elements by a `name` of component on wrapper components.
Expand All @@ -55,6 +84,6 @@ buttonWrapper.trigger('click')
Using a find option object, Vue Test Utils allows for selecting elements by `$ref` on wrapper components.

```js
const buttonWrapper = wrapper.find({ ref: 'myButton' })
const buttonWrapper = wrapper.find({ ref: 'dynamic-my-button-ref' })
buttonWrapper.trigger('click')
```