Skip to content

Commit 950763f

Browse files
stevegrunwelleddyerburgh
authored andcommittedJun 12, 2019
fix: respect "hidden" attributes in isVisible() (#1257)
Elements that are hidden via the HTML `hidden` attribute were being reported as being visible by the `isVisible()` method, even though they were not actually visible in the DOM.
1 parent 8a74a15 commit 950763f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed
 

‎packages/test-utils/src/wrapper.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,10 @@ export default class Wrapper implements BaseWrapper {
270270
let element = this.element
271271
while (element) {
272272
if (
273-
element.style &&
274-
(element.style.visibility === 'hidden' ||
275-
element.style.display === 'none')
273+
element.hidden ||
274+
(element.style &&
275+
(element.style.visibility === 'hidden' ||
276+
element.style.display === 'none'))
276277
) {
277278
return false
278279
}

‎test/specs/wrapper/isVisible.spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ describeWithShallowAndMount('isVisible', mountingMethod => {
3232
expect(element.isVisible()).to.equal(false)
3333
})
3434

35+
it('returns false if element has hidden attribute', () => {
36+
const compiled = compileToFunctions(
37+
'<div><div><span class="visible" hidden></span></div></div>'
38+
)
39+
const wrapper = mountingMethod(compiled)
40+
const element = wrapper.find('.visible')
41+
expect(element.isVisible()).to.equal(false)
42+
})
43+
3544
it('returns true if element has v-show true', async () => {
3645
const wrapper = mountingMethod(ComponentWithVShow)
3746
wrapper.vm.$set(wrapper.vm, 'ready', true)

0 commit comments

Comments
 (0)
Please sign in to comment.