diff --git a/docs/en/api/selectors.md b/docs/en/api/selectors.md index 3e767de88..4e0c0bdf0 100644 --- a/docs/en/api/selectors.md +++ b/docs/en/api/selectors.md @@ -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' }) diff --git a/test/unit/specs/mount/Wrapper/find.spec.js b/test/unit/specs/mount/Wrapper/find.spec.js index e7cf10e53..1ddbb5ce8 100644 --- a/test/unit/specs/mount/Wrapper/find.spec.js +++ b/test/unit/specs/mount/Wrapper/find.spec.js @@ -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) diff --git a/test/unit/specs/mount/Wrapper/findAll.spec.js b/test/unit/specs/mount/Wrapper/findAll.spec.js index bc47d0566..eb74a2a1a 100644 --- a/test/unit/specs/mount/Wrapper/findAll.spec.js +++ b/test/unit/specs/mount/Wrapper/findAll.spec.js @@ -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('
') const wrapper = mount(compiled)