Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update selectors.md #2088

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 30 additions & 1 deletion docs/api/selectors.md
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')
```