Skip to content

Commit 3cffbab

Browse files
authored
refactor: rename visible to isVisible (#425)
breaking change
1 parent e85f20a commit 3cffbab

File tree

8 files changed

+59
-37
lines changed

8 files changed

+59
-37
lines changed

docs/en/SUMMARY.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
* [text](api/wrapper/text.md)
4848
* [trigger](api/wrapper/trigger.md)
4949
* [update](api/wrapper/update.md)
50-
* [visible](api/wrapper/visible.md)
50+
* [isVisible](api/wrapper/isVisible.md)
5151
* [WrapperArray](api/wrapper-array/README.md)
5252
* [at](api/wrapper-array/at.md)
5353
* [contains](api/wrapper-array/contains.md)
@@ -62,7 +62,7 @@
6262
* [setProps](api/wrapper-array/setProps.md)
6363
* [trigger](api/wrapper-array/trigger.md)
6464
* [update](api/wrapper-array/update.md)
65-
* [visible](api/wrapper-array/visible.md)
65+
* [isVisible](api/wrapper-array/isVisible.md)
6666
* [components](api/components/README.md)
6767
* [TransitionStub](api/components/TransitionStub.md)
6868
* [TransitionGroupStub](api/components/TransitionGroupStub.md)

docs/en/api/wrapper-array/visible.md renamed to docs/en/api/wrapper-array/isVisible.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { expect } from 'chai'
1616
import Foo from './Foo.vue'
1717

1818
const wrapper = mount(Foo)
19-
expect(wrapper.visible()).toBe(true)
20-
expect(wrapper.findAll('.is-not-visible').visible()).toBe(false)
21-
expect(wrapper.findAll('.is-visible').visible()).toBe(true)
19+
expect(wrapper.isVisible()).toBe(true)
20+
expect(wrapper.findAll('.is-not-visible').isVisible()).toBe(false)
21+
expect(wrapper.findAll('.is-visible').isVisible()).toBe(true)
2222
```

docs/en/api/wrapper/visible.md renamed to docs/en/api/wrapper/isVisible.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# visible()
1+
# isVisible()
22

33
Assert `Wrapper` is visible.
44

@@ -16,6 +16,6 @@ import { expect } from 'chai'
1616
import Foo from './Foo.vue'
1717

1818
const wrapper = mount(Foo)
19-
expect(wrapper.visible()).toBe(true)
20-
expect(wrapper.find('.is-not-visible').visible()).toBe(false)
19+
expect(wrapper.isVisible()).toBe(true)
20+
expect(wrapper.find('.is-not-visible').isVisible()).toBe(false)
2121
```

docs/ja/SUMMARY.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
* [text](api/wrapper/text.md)
4848
* [trigger](api/wrapper/trigger.md)
4949
* [update](api/wrapper/update.md)
50-
* [visible](api/wrapper/visible.md)
50+
* [isVisible](api/wrapper/isVisible.md)
5151
* [WrapperArray](api/wrapper-array/README.md)
5252
* [at](api/wrapper-array/at.md)
5353
* [contains](api/wrapper-array/contains.md)
@@ -61,7 +61,7 @@
6161
* [setProps](api/wrapper-array/setProps.md)
6262
* [trigger](api/wrapper-array/trigger.md)
6363
* [update](api/wrapper-array/update.md)
64-
* [visible](api/wrapper-array/visible.md)
64+
* [isVisible](api/wrapper-array/isVisible.md)
6565
* [コンポーネント](api/components/README.md)
6666
* [TransitionStub](api/components/TransitionStub.md)
6767
* [TransitionGroupStub](api/components/TransitionGroupStub.md)

docs/ja/api/wrapper-array/visible.md renamed to docs/ja/api/wrapper-array/isVisible.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# visible()
1+
# isVisible()
22

33
`WrapperArray` 内のすべての `Wrapper` が表示されているかアサートします。
44

@@ -16,7 +16,7 @@ import { expect } from 'chai'
1616
import Foo from './Foo.vue'
1717

1818
const wrapper = mount(Foo)
19-
expect(wrapper.visible()).toBe(true)
20-
expect(wrapper.findAll('.is-not-visible').visible()).toBe(false)
21-
expect(wrapper.findAll('.is-visible').visible()).toBe(true)
19+
expect(wrapper.isVisible()).toBe(true)
20+
expect(wrapper.findAll('.is-not-visible').isVisible()).toBe(false)
21+
expect(wrapper.findAll('.is-visible').isVisible()).toBe(true)
2222
```

docs/ja/api/wrapper/visible.md renamed to docs/ja/api/wrapper/isVisible.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# visible()
1+
# isVisible()
22

33
`Wrapper` が表示されているかアサートします。
44

@@ -16,6 +16,6 @@ import { expect } from 'chai'
1616
import Foo from './Foo.vue'
1717

1818
const wrapper = mount(Foo)
19-
expect(wrapper.visible()).toBe(true)
20-
expect(wrapper.find('.is-not-visible').visible()).toBe(false)
19+
expect(wrapper.isVisible()).toBe(true)
20+
expect(wrapper.find('.is-not-visible').isVisible()).toBe(false)
2121
```

src/wrappers/wrapper.js

+22
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ export default class Wrapper implements BaseWrapper {
133133
* Utility to check wrapper is visible. Returns false if a parent element has display: none or visibility: hidden style.
134134
*/
135135
visible (): boolean {
136+
warn('visible has been deprecated and will be removed in version 1, use isVisible instead')
137+
136138
let element = this.element
137139

138140
if (!element) {
@@ -328,6 +330,26 @@ export default class Wrapper implements BaseWrapper {
328330
return this.vnode.children === undefined || this.vnode.children.length === 0
329331
}
330332

333+
/**
334+
* Checks if node is visible
335+
*/
336+
isVisible (): boolean {
337+
let element = this.element
338+
339+
if (!element) {
340+
return false
341+
}
342+
343+
while (element) {
344+
if (element.style && (element.style.visibility === 'hidden' || element.style.display === 'none')) {
345+
return false
346+
}
347+
element = element.parentElement
348+
}
349+
350+
return true
351+
}
352+
331353
/**
332354
* Checks if wrapper is a vue instance
333355
*/

test/specs/wrapper/visible.spec.js renamed to test/specs/wrapper/isVisible.spec.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@ import ComponentWithVShow from '~resources/components/component-with-v-show.vue'
33
import ComponentWithVIf from '~resources/components/component-with-v-if.vue'
44
import { describeWithShallowAndMount } from '~resources/test-utils'
55

6-
describeWithShallowAndMount('visible', (mountingMethod) => {
6+
describeWithShallowAndMount('isVisible', (mountingMethod) => {
77
it('returns true if element has no inline style', () => {
88
const compiled = compileToFunctions('<div><div><span class="visible"></span></div></div>')
99
const wrapper = mountingMethod(compiled)
1010
const element = wrapper.find('.visible')
11-
expect(element.visible()).to.equal(true)
11+
expect(element.isVisible()).to.equal(true)
1212
})
1313

1414
it('returns false if element has inline style display: none', () => {
1515
const compiled = compileToFunctions('<div><div><span style="display: none;" class="visible"></span></div></div>')
1616
const wrapper = mountingMethod(compiled)
1717
const element = wrapper.find('.visible')
18-
expect(element.visible()).to.equal(false)
18+
expect(element.isVisible()).to.equal(false)
1919
})
2020

2121
it('returns false if element has inline style visibility: hidden', () => {
2222
const compiled = compileToFunctions('<div><div><span style="visibility: hidden;" class="visible"></span></div></div>')
2323
const wrapper = mountingMethod(compiled)
2424
const element = wrapper.find('.visible')
25-
expect(element.visible()).to.equal(false)
25+
expect(element.isVisible()).to.equal(false)
2626
})
2727

2828
it('returns true if element has v-show true', () => {
@@ -31,10 +31,10 @@ describeWithShallowAndMount('visible', (mountingMethod) => {
3131
wrapper.update()
3232

3333
const notReadyElement = wrapper.find('.not-ready')
34-
expect(notReadyElement.visible()).to.equal(false)
34+
expect(notReadyElement.isVisible()).to.equal(false)
3535

3636
const readyElement = wrapper.find('.parent.ready')
37-
expect(readyElement.visible()).to.equal(true)
37+
expect(readyElement.isVisible()).to.equal(true)
3838
})
3939

4040
it('returns false if element has v-show true', () => {
@@ -43,10 +43,10 @@ describeWithShallowAndMount('visible', (mountingMethod) => {
4343
wrapper.update()
4444

4545
const notReadyElement = wrapper.find('.not-ready')
46-
expect(notReadyElement.visible()).to.equal(false)
46+
expect(notReadyElement.isVisible()).to.equal(false)
4747

4848
const readyElement = wrapper.find('.parent.ready')
49-
expect(readyElement.visible()).to.equal(true)
49+
expect(readyElement.isVisible()).to.equal(true)
5050
})
5151

5252
it('returns true if parent element has v-show true', () => {
@@ -55,10 +55,10 @@ describeWithShallowAndMount('visible', (mountingMethod) => {
5555
wrapper.update()
5656

5757
const notReadyElement = wrapper.find('.not-ready')
58-
expect(notReadyElement.visible()).to.equal(false)
58+
expect(notReadyElement.isVisible()).to.equal(false)
5959

6060
const readyChildElement = wrapper.find('.child.ready')
61-
expect(readyChildElement.visible()).to.equal(true)
61+
expect(readyChildElement.isVisible()).to.equal(true)
6262
})
6363

6464
it('returns false if parent element has v-show false', () => {
@@ -67,10 +67,10 @@ describeWithShallowAndMount('visible', (mountingMethod) => {
6767
wrapper.update()
6868

6969
const notReadyElement = wrapper.find('.not-ready')
70-
expect(notReadyElement.visible()).to.equal(false)
70+
expect(notReadyElement.isVisible()).to.equal(false)
7171

7272
const readyChildElement = wrapper.find('.child.ready')
73-
expect(readyChildElement.visible()).to.equal(true)
73+
expect(readyChildElement.isVisible()).to.equal(true)
7474
})
7575

7676
it('returns false if root element has v-show false and parent has v-show true', () => {
@@ -80,10 +80,10 @@ describeWithShallowAndMount('visible', (mountingMethod) => {
8080
wrapper.update()
8181

8282
const notReadyElement = wrapper.find('.not-ready')
83-
expect(notReadyElement.visible()).to.equal(false)
83+
expect(notReadyElement.isVisible()).to.equal(false)
8484

8585
const readyChildElement = wrapper.find('.child.ready')
86-
expect(readyChildElement.visible()).to.equal(false)
86+
expect(readyChildElement.isVisible()).to.equal(false)
8787
})
8888

8989
it('returns false if root element has v-show true and parent has v-show false', () => {
@@ -93,10 +93,10 @@ describeWithShallowAndMount('visible', (mountingMethod) => {
9393
wrapper.update()
9494

9595
const notReadyElement = wrapper.find('.not-ready')
96-
expect(notReadyElement.visible()).to.equal(true)
96+
expect(notReadyElement.isVisible()).to.equal(true)
9797

9898
const readyChildElement = wrapper.find('.child.ready')
99-
expect(readyChildElement.visible()).to.equal(false)
99+
expect(readyChildElement.isVisible()).to.equal(false)
100100
})
101101

102102
it('returns true if all elements are visible', () => {
@@ -106,7 +106,7 @@ describeWithShallowAndMount('visible', (mountingMethod) => {
106106
wrapper.update()
107107

108108
const readyChildElement = wrapper.find('.ready')
109-
expect(readyChildElement.visible()).to.equal(true)
109+
expect(readyChildElement.isVisible()).to.equal(true)
110110
})
111111

112112
it('returns false if one element is not visible', () => {
@@ -116,22 +116,22 @@ describeWithShallowAndMount('visible', (mountingMethod) => {
116116
wrapper.update()
117117

118118
const readyChildElement = wrapper.find('.ready, .not-ready')
119-
expect(readyChildElement.visible()).to.equal(false)
119+
expect(readyChildElement.isVisible()).to.equal(false)
120120
})
121121

122122
it('fails if one element is absent', () => {
123123
const wrapper = mountingMethod(ComponentWithVIf)
124124
wrapper.vm.$set(wrapper.vm, 'ready', false)
125125
wrapper.update()
126126

127-
const fn = () => wrapper.find('.child.ready').visible()
127+
const fn = () => wrapper.find('.child.ready').isVisible()
128128
expect(fn).to.throw()
129129
})
130130

131131
it('returns true if one element is present', () => {
132132
const wrapper = mountingMethod(ComponentWithVIf)
133133
wrapper.vm.$set(wrapper.vm, 'ready', true)
134134
wrapper.update()
135-
expect(wrapper.find('.child.ready').visible()).to.equal(true)
135+
expect(wrapper.find('.child.ready').isVisible()).to.equal(true)
136136
})
137137
})

0 commit comments

Comments
 (0)