Skip to content

test: name in options object #348

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

Merged
merged 1 commit into from
Jan 11, 2018
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion docs/en/api/selectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ expect(wrapper.is(Foo)).toBe(true)

### Name

Using a find option object, `vue-test-utils` allows for selecting elements by `name` on wrapper components.
Using a find option object, `vue-test-utils` allows for selecting elements by a `name` of component on wrapper components.

```js
const buttonWrapper = wrapper.find({ name: 'my-button' })
Expand Down
5 changes: 5 additions & 0 deletions test/unit/specs/mount/Wrapper/find.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ describe('find', () => {
expect(wrapper.find(TestComponent).isVueComponent).to.equal(true)
})

it('returns a Wrapper matching a component name in options object', () => {
const wrapper = mount(ComponentWithChild)
expect(wrapper.find({ name: 'component' }).name()).to.equal('component')
})

it('returns Wrapper of Vue Component matching the ref in options object', () => {
const wrapper = mount(ComponentWithChild)
expect(wrapper.find({ ref: 'child' }).isVueComponent).to.equal(true)
Expand Down
7 changes: 7 additions & 0 deletions test/unit/specs/mount/Wrapper/findAll.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ describe('findAll', () => {
expect(preArray.wrappers).to.deep.equal([])
})

it('returns an array of Wrapper of elements matching a component name in options object', () => {
const wrapper = mount(ComponentWithChild)
const wrapperArray = wrapper.findAll({ name: 'component' })
expect(wrapperArray.at(0).name()).to.equal('component')
expect(wrapperArray.length).to.equal(1)
})

it('returns an array of Wrapper of elements matching the ref in options object', () => {
const compiled = compileToFunctions('<div><div ref="foo" /></div>')
const wrapper = mount(compiled)
Expand Down