Skip to content

Commit a0bef79

Browse files
committed
fix: check for element in hasAttribute
1 parent e12ddc7 commit a0bef79

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/wrappers/wrapper.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ export default class Wrapper implements BaseWrapper {
217217
}
218218
return vmCtorMatchesName(this.vm, selector.name)
219219
}
220-
return this.element.getAttribute && this.element.matches(selector)
220+
221+
return !!(this.element &&
222+
this.element.getAttribute &&
223+
this.element.matches(selector))
221224
}
222225

223226
/**

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ describe('is', () => {
2222
expect(wrapper.is('#div')).to.equal(true)
2323
})
2424

25+
it('returns false if wrapper does not contain element', () => {
26+
const wrapper = mount(ComponentWithChild)
27+
wrapper.element = null
28+
expect(wrapper.is('a')).to.equal(false)
29+
})
30+
2531
it('returns true if root node matches Vue Component selector', () => {
2632
const wrapper = mount(ComponentWithChild)
2733
const component = wrapper.findAll(Component).at(0)

0 commit comments

Comments
 (0)