diff --git a/src/utils/isElementVisible.ts b/src/utils/isElementVisible.ts index 82ccb7abc..27aa0cfd4 100644 --- a/src/utils/isElementVisible.ts +++ b/src/utils/isElementVisible.ts @@ -9,7 +9,7 @@ function isStyleVisible(element: T) { return false } - const { display, visibility, opacity } = element.style + const { display, visibility, opacity } = getComputedStyle(element) return ( display !== 'none' && diff --git a/tests/isVisible.spec.ts b/tests/isVisible.spec.ts index 0ac38876b..d01230766 100644 --- a/tests/isVisible.spec.ts +++ b/tests/isVisible.spec.ts @@ -109,4 +109,19 @@ describe('isVisible', () => { expect(wrapper.html()).toContain('Item: 1') expect(wrapper.html()).not.toContain('Item: 2') }) + + it('should take css into account', async () => { + const style = document.createElement('style') + style.type = 'text/css' + document.head.appendChild(style) + style.sheet!.insertRule('.opacity-0 { opacity: 0; }') + + const wrapper = mount({ + template: '
' + }) + + expect(wrapper.get('#my-div').isVisible()).toBe(false) + + document.head.removeChild(style) + }) })