Skip to content

Commit 9ef35c8

Browse files
committed
fix: return boolean in hasAttribute
1 parent 705e8e2 commit 9ef35c8

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/wrappers/wrapper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default class Wrapper implements BaseWrapper {
6666
throwError('wrapper.hasAttribute() must be passed value as a string')
6767
}
6868

69-
return this.element && this.element.getAttribute(attribute) === value
69+
return !!(this.element && this.element.getAttribute(attribute) === value)
7070
}
7171

7272
/**

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ describe('hasAttribute', () => {
1616
expect(wrapper.hasAttribute('attribute', 'value')).to.equal(false)
1717
})
1818

19+
it('returns false if wrapper element is null', () => {
20+
const compiled = compileToFunctions('<div />')
21+
const wrapper = mount(compiled)
22+
wrapper.element = null
23+
expect(wrapper.hasAttribute('attribute', 'value')).to.equal(false)
24+
})
25+
1926
it('throws an error if attribute is not a string', () => {
2027
const compiled = compileToFunctions('<div />')
2128
const wrapper = mount(compiled)

0 commit comments

Comments
 (0)