Skip to content

Commit ad6af6f

Browse files
committed
feat(is): throw error if component selector does not have name
1 parent 03742e9 commit ad6af6f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/wrappers/wrapper.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ export default class Wrapper implements BaseWrapper {
206206
if (!this.isVueComponent) {
207207
return false
208208
}
209-
// TODO: Throw error if component does not have name
209+
if (typeof selector.name !== 'string') {
210+
throwError('a Component used as a selector must have a name property')
211+
}
210212
return vmCtorMatchesName(this.vm, selector.name)
211213
}
212214
return this.element.getAttribute && this.element.matches(selector)

test/integration/specs/mount/Wrapper/is.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ describe('is', () => {
5252
expect(wrapper.is('#p')).to.equal(false)
5353
})
5454

55+
it('throws error if component passed to use as identifier does not have a name', () => {
56+
const compiled = compileToFunctions('<div />')
57+
const wrapper = mount(compiled)
58+
59+
const message = '[vue-test-utils]: a Component used as a selector must have a name property'
60+
const fn = () => wrapper.is({ render: () => {} })
61+
expect(fn).to.throw().with.property('message', message)
62+
})
63+
5564
it('throws an error if selector is not a valid selector', () => {
5665
const compiled = compileToFunctions('<div />')
5766
const wrapper = mount(compiled)

0 commit comments

Comments
 (0)