Skip to content

Commit ca5a68b

Browse files
authored
Update selectors.md
Added a component example, with a template, to make it clear how the selectors can work
1 parent 9627a80 commit ca5a68b

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

Diff for: docs/api/selectors.md

+30-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,35 @@ expect(wrapper.is(Foo)).toBe(true)
4141

4242
### Find Option Object
4343

44+
Suppose you have the following component
45+
```js
46+
// MyButtonComponent.vue
47+
48+
<template>
49+
<button class="btn" name="my-button" :ref="myButtonRef">Click My Button</button>
50+
</template>
51+
<script lang="ts">
52+
export default defineComponent({
53+
name: 'MyButtonComponent',
54+
computed: {
55+
myButtonRef() {
56+
return 'dynamic-my-button-ref';
57+
}
58+
}
59+
</script>
60+
61+
or
62+
63+
const MyButtonComponent = {
64+
template: '<button class="btn" name="my-button" :ref="myButtonRef">Click My Button</button>',
65+
computed: {
66+
myButtonRef() {
67+
return 'dynamic-my-button-ref';
68+
}
69+
}
70+
};
71+
```
72+
4473
#### Name
4574
4675
Using a find option object, Vue Test Utils allows for selecting elements by a `name` of component on wrapper components.
@@ -55,6 +84,6 @@ buttonWrapper.trigger('click')
5584
Using a find option object, Vue Test Utils allows for selecting elements by `$ref` on wrapper components.
5685
5786
```js
58-
const buttonWrapper = wrapper.find({ ref: 'myButton' })
87+
const buttonWrapper = wrapper.find({ ref: 'dynamic-my-button-ref' })
5988
buttonWrapper.trigger('click')
6089
```

0 commit comments

Comments
 (0)