Skip to content

add isVisible typos and missing tests #464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions flow/wrapper.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ declare interface BaseWrapper { // eslint-disable-line no-undef
html(): string | void,
is(selector: Selector): boolean | void,
isEmpty(): boolean | void,
isVisible(): boolean | void,
isVueInstance(): boolean | void,
name(): string | void,
props(): { [name: string]: any } | void,
Expand Down
4 changes: 4 additions & 0 deletions packages/test-utils/src/error-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export default class ErrorWrapper implements BaseWrapper {
throwError(`find did not return ${this.selector}, cannot call isEmpty() on empty Wrapper`)
}

isVisible (): void {
throwError(`find did not return ${this.selector}, cannot call isVisible() on empty Wrapper`)
}

isVueInstance (): void {
throwError(`find did not return ${this.selector}, cannot call isVueInstance() on empty Wrapper`)
}
Expand Down
6 changes: 6 additions & 0 deletions packages/test-utils/src/wrapper-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ export default class WrapperArray implements BaseWrapper {
return this.wrappers.every(wrapper => wrapper.isEmpty())
}

isVisible (): boolean {
this.throwErrorIfWrappersIsEmpty('isVisible')

return this.wrappers.every(wrapper => wrapper.isVisible())
}

isVueInstance (): boolean {
this.throwErrorIfWrappersIsEmpty('isVueInstance')

Expand Down
2 changes: 1 addition & 1 deletion test/specs/error-wrapper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { compileToFunctions } from 'vue-template-compiler'

describe('ErrorWrapper', () => {
const methods = ['at', 'attributes', 'classes', 'contains', 'emitted', 'emittedByOrder', 'hasAttribute',
'hasClass', 'hasProp', 'hasStyle', 'find', 'findAll', 'filter', 'html', 'text', 'is', 'isEmpty', 'isVueInstance',
'hasClass', 'hasProp', 'hasStyle', 'find', 'findAll', 'filter', 'html', 'text', 'is', 'isEmpty', 'isVisible', 'isVueInstance',
'name', 'props', 'setComputed', 'setMethods', 'setData', 'setProps', 'trigger', 'update', 'destroy']
methods.forEach((method) => {
it(`${method} throws error when called`, () => {
Expand Down
14 changes: 12 additions & 2 deletions test/specs/wrapper-array.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('WrapperArray', () => {
})

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

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

it('isVisible returns true if every wrapper.isVisible() returns true', () => {
const wrapperArray = getWrapperArray([{ isVisible: () => true }, { isVisible: () => true }])
expect(wrapperArray.isVisible()).to.equal(true)
})

it('isVisible returns false if not every wrapper.isVisible() returns true', () => {
const wrapperArray = getWrapperArray([{ isVisible: () => true }, { isVisible: () => false }])
expect(wrapperArray.isVisible()).to.equal(false)
})

it('isVueInstance returns true if every wrapper.isVueInstance() returns true', () => {
const wrapperArray = getWrapperArray([{ isVueInstance: () => true }, { isVueInstance: () => true }])
expect(wrapperArray.isVueInstance()).to.equal(true)
Expand Down
32 changes: 32 additions & 0 deletions test/specs/wrapper-array/isVisible.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { compileToFunctions } from 'vue-template-compiler'
import { mount } from '~vue/test-utils'

describe('isVisible', () => {
it('returns true if node has no inline style', () => {
const compiled = compileToFunctions('<div><p /></div>')
const wrapper = mount(compiled)

expect(wrapper.findAll('p').isVisible()).to.equal(true)
})

it('returns false if node has inline style display: none', () => {
const compiled = compileToFunctions('<div><p style="display: none;"><p/></div>')
const wrapper = mount(compiled)

expect(wrapper.findAll('p').isVisible()).to.equal(false)
})

it('returns false if node has visibility: hidden', () => {
const compiled = compileToFunctions('<div><p style="visibility: hidden;"><p/></div>')
const wrapper = mount(compiled)

expect(wrapper.findAll('p').isVisible()).to.equal(false)
})

it('throws error if wrapper array contains no items', () => {
const compiled = compileToFunctions('<div />')
const message = '[vue-test-utils]: isVisible cannot be called on 0 items'
const fn = () => mount(compiled).findAll('p').isVisible('p')
expect(fn).to.throw().with.property('message', message)
})
})