Skip to content

Commit 18eb193

Browse files
Diego Jaraeddyerburgh
Diego Jara
authored andcommitted
fix: add isVisible typos and missing tests (#464)
1 parent a0edc22 commit 18eb193

File tree

6 files changed

+56
-3
lines changed

6 files changed

+56
-3
lines changed

flow/wrapper.flow.js

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ declare interface BaseWrapper { // eslint-disable-line no-undef
2424
html(): string | void,
2525
is(selector: Selector): boolean | void,
2626
isEmpty(): boolean | void,
27+
isVisible(): boolean | void,
2728
isVueInstance(): boolean | void,
2829
name(): string | void,
2930
props(): { [name: string]: any } | void,

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

+4
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ export default class ErrorWrapper implements BaseWrapper {
8181
throwError(`find did not return ${this.selector}, cannot call isEmpty() on empty Wrapper`)
8282
}
8383

84+
isVisible (): void {
85+
throwError(`find did not return ${this.selector}, cannot call isVisible() on empty Wrapper`)
86+
}
87+
8488
isVueInstance (): void {
8589
throwError(`find did not return ${this.selector}, cannot call isVueInstance() on empty Wrapper`)
8690
}

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

+6
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ export default class WrapperArray implements BaseWrapper {
118118
return this.wrappers.every(wrapper => wrapper.isEmpty())
119119
}
120120

121+
isVisible (): boolean {
122+
this.throwErrorIfWrappersIsEmpty('isVisible')
123+
124+
return this.wrappers.every(wrapper => wrapper.isVisible())
125+
}
126+
121127
isVueInstance (): boolean {
122128
this.throwErrorIfWrappersIsEmpty('isVueInstance')
123129

test/specs/error-wrapper.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { compileToFunctions } from 'vue-template-compiler'
33

44
describe('ErrorWrapper', () => {
55
const methods = ['at', 'attributes', 'classes', 'contains', 'emitted', 'emittedByOrder', 'hasAttribute',
6-
'hasClass', 'hasProp', 'hasStyle', 'find', 'findAll', 'filter', 'html', 'text', 'is', 'isEmpty', 'isVueInstance',
6+
'hasClass', 'hasProp', 'hasStyle', 'find', 'findAll', 'filter', 'html', 'text', 'is', 'isEmpty', 'isVisible', 'isVueInstance',
77
'name', 'props', 'setComputed', 'setMethods', 'setData', 'setProps', 'trigger', 'update', 'destroy']
88
methods.forEach((method) => {
99
it(`${method} throws error when called`, () => {

test/specs/wrapper-array.spec.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('WrapperArray', () => {
3232
})
3333

3434
const methods = ['at', 'attributes', 'classes', 'contains', 'emitted', 'emittedByOrder', 'hasAttribute',
35-
'hasClass', 'hasProp', 'hasStyle', 'find', 'findAll', 'html', 'text', 'is', 'isEmpty', 'isVueInstance',
35+
'hasClass', 'hasProp', 'hasStyle', 'find', 'findAll', 'html', 'text', 'is', 'isEmpty', 'isVisible', 'isVueInstance',
3636
'name', 'props', 'setComputed', 'setMethods', 'setData', 'setProps', 'trigger', 'update', 'destroy']
3737
methods.forEach((method) => {
3838
it(`throws error if ${method} is called when there are no items in wrapper array`, () => {
@@ -46,7 +46,7 @@ describe('WrapperArray', () => {
4646
})
4747

4848
it(`${method} throws error if called when there are items in wrapper array`, () => {
49-
if (['at', 'contains', 'hasAttribute', 'hasClass', 'hasProp', 'hasStyle', 'is', 'isEmpty', 'isVueInstance',
49+
if (['at', 'contains', 'hasAttribute', 'hasClass', 'hasProp', 'hasStyle', 'is', 'isEmpty', 'isVisible', 'isVueInstance',
5050
'setComputed', 'setMethods', 'setData', 'setProps', 'trigger', 'update', 'destroy'].includes(method)) {
5151
return
5252
}
@@ -176,6 +176,16 @@ describe('WrapperArray', () => {
176176
expect(wrapperArray.isEmpty()).to.equal(false)
177177
})
178178

179+
it('isVisible returns true if every wrapper.isVisible() returns true', () => {
180+
const wrapperArray = getWrapperArray([{ isVisible: () => true }, { isVisible: () => true }])
181+
expect(wrapperArray.isVisible()).to.equal(true)
182+
})
183+
184+
it('isVisible returns false if not every wrapper.isVisible() returns true', () => {
185+
const wrapperArray = getWrapperArray([{ isVisible: () => true }, { isVisible: () => false }])
186+
expect(wrapperArray.isVisible()).to.equal(false)
187+
})
188+
179189
it('isVueInstance returns true if every wrapper.isVueInstance() returns true', () => {
180190
const wrapperArray = getWrapperArray([{ isVueInstance: () => true }, { isVueInstance: () => true }])
181191
expect(wrapperArray.isVueInstance()).to.equal(true)
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { compileToFunctions } from 'vue-template-compiler'
2+
import { mount } from '~vue/test-utils'
3+
4+
describe('isVisible', () => {
5+
it('returns true if node has no inline style', () => {
6+
const compiled = compileToFunctions('<div><p /></div>')
7+
const wrapper = mount(compiled)
8+
9+
expect(wrapper.findAll('p').isVisible()).to.equal(true)
10+
})
11+
12+
it('returns false if node has inline style display: none', () => {
13+
const compiled = compileToFunctions('<div><p style="display: none;"><p/></div>')
14+
const wrapper = mount(compiled)
15+
16+
expect(wrapper.findAll('p').isVisible()).to.equal(false)
17+
})
18+
19+
it('returns false if node has visibility: hidden', () => {
20+
const compiled = compileToFunctions('<div><p style="visibility: hidden;"><p/></div>')
21+
const wrapper = mount(compiled)
22+
23+
expect(wrapper.findAll('p').isVisible()).to.equal(false)
24+
})
25+
26+
it('throws error if wrapper array contains no items', () => {
27+
const compiled = compileToFunctions('<div />')
28+
const message = '[vue-test-utils]: isVisible cannot be called on 0 items'
29+
const fn = () => mount(compiled).findAll('p').isVisible('p')
30+
expect(fn).to.throw().with.property('message', message)
31+
})
32+
})

0 commit comments

Comments
 (0)