diff --git a/flow/wrapper.flow.js b/flow/wrapper.flow.js index b4f3aa3a8..f41d5228a 100644 --- a/flow/wrapper.flow.js +++ b/flow/wrapper.flow.js @@ -18,11 +18,6 @@ declare interface BaseWrapper { emittedByOrder(): Array<{ name: string, args: Array }> | void; exists(): boolean; filter(predicate: Function): WrapperArray | void; - visible(): boolean | void; - hasAttribute(attribute: string, value: string): boolean | void; - hasClass(className: string): boolean | void; - hasProp(prop: string, value: string): boolean | void; - hasStyle(style: string, value: string): boolean | void; find(selector: Selector): Wrapper | void; findAll(selector: Selector): WrapperArray | void; html(): string | void; @@ -34,7 +29,6 @@ declare interface BaseWrapper { props(key?: string): { [name: string]: any } | any | void; text(): string | void; setData(data: Object): void; - setComputed(computed: Object): void; setMethods(methods: Object): void; setValue(value: any): void; setChecked(checked?: boolean): void; diff --git a/packages/test-utils/src/wrapper-array.js b/packages/test-utils/src/wrapper-array.js index 44f3cd89f..cc9b86993 100644 --- a/packages/test-utils/src/wrapper-array.js +++ b/packages/test-utils/src/wrapper-array.js @@ -61,12 +61,6 @@ export default class WrapperArray implements BaseWrapper { return new WrapperArray(this.wrappers.filter(predicate)) } - visible (): boolean { - this.throwErrorIfWrappersIsEmpty('visible') - - return this.length > 0 && this.wrappers.every(wrapper => wrapper.visible()) - } - emitted (): void { this.throwErrorIfWrappersIsEmpty('emitted') @@ -85,32 +79,6 @@ export default class WrapperArray implements BaseWrapper { ) } - hasAttribute (attribute: string, value: string): boolean { - this.throwErrorIfWrappersIsEmpty('hasAttribute') - - return this.wrappers.every(wrapper => - wrapper.hasAttribute(attribute, value) - ) - } - - hasClass (className: string): boolean { - this.throwErrorIfWrappersIsEmpty('hasClass') - - return this.wrappers.every(wrapper => wrapper.hasClass(className)) - } - - hasProp (prop: string, value: string): boolean { - this.throwErrorIfWrappersIsEmpty('hasProp') - - return this.wrappers.every(wrapper => wrapper.hasProp(prop, value)) - } - - hasStyle (style: string, value: string): boolean { - this.throwErrorIfWrappersIsEmpty('hasStyle') - - return this.wrappers.every(wrapper => wrapper.hasStyle(style, value)) - } - findAll (): void { this.throwErrorIfWrappersIsEmpty('findAll') @@ -195,12 +163,6 @@ export default class WrapperArray implements BaseWrapper { } } - setComputed (computed: Object): void { - this.throwErrorIfWrappersIsEmpty('setComputed') - - this.wrappers.forEach(wrapper => wrapper.setComputed(computed)) - } - setData (data: Object): void { this.throwErrorIfWrappersIsEmpty('setData') diff --git a/packages/test-utils/src/wrapper.js b/packages/test-utils/src/wrapper.js index e12fc1c14..2c6bd4319 100644 --- a/packages/test-utils/src/wrapper.js +++ b/packages/test-utils/src/wrapper.js @@ -234,139 +234,6 @@ export default class Wrapper implements BaseWrapper { return new WrapperArray(wrappers) } - /** - * Checks if wrapper has an attribute with matching value - */ - hasAttribute (attribute: string, value: string): boolean { - warn( - `hasAttribute() has been deprecated and will be ` + - `removed in version 1.0.0. Use attributes() ` + - `instead—https://vue-test-utils.vuejs.org/api/wrapper/attributes.html` - ) - - if (typeof attribute !== 'string') { - throwError( - `wrapper.hasAttribute() must be passed attribute as a string` - ) - } - - if (typeof value !== 'string') { - throwError( - `wrapper.hasAttribute() must be passed value as a string` - ) - } - - return !!(this.element.getAttribute(attribute) === value) - } - - /** - * Asserts wrapper has a class name - */ - hasClass (className: string): boolean { - warn( - `hasClass() has been deprecated and will be removed ` + - `in version 1.0.0. Use classes() ` + - `instead—https://vue-test-utils.vuejs.org/api/wrapper/classes.html` - ) - let targetClass = className - - if (typeof targetClass !== 'string') { - throwError('wrapper.hasClass() must be passed a string') - } - - // if $style is available and has a matching target, use that instead. - if (this.vm && this.vm.$style && this.vm.$style[targetClass]) { - targetClass = this.vm.$style[targetClass] - } - - const containsAllClasses = targetClass - .split(' ') - .every(target => this.element.classList.contains(target)) - - return !!(this.element && containsAllClasses) - } - - /** - * Asserts wrapper has a prop name - */ - hasProp (prop: string, value: string): boolean { - warn( - `hasProp() has been deprecated and will be removed ` + - `in version 1.0.0. Use props() ` + - `instead—https://vue-test-utils.vuejs.org/api/wrapper/props.html` - ) - - if (!this.isVueInstance()) { - throwError('wrapper.hasProp() must be called on a Vue instance') - } - if (typeof prop !== 'string') { - throwError('wrapper.hasProp() must be passed prop as a string') - } - - // $props object does not exist in Vue 2.1.x, so use - // $options.propsData instead - if ( - this.vm && - this.vm.$options && - this.vm.$options.propsData && - this.vm.$options.propsData[prop] === value - ) { - return true - } - - return !!this.vm && !!this.vm.$props && this.vm.$props[prop] === value - } - - /** - * Checks if wrapper has a style with value - */ - hasStyle (style: string, value: string): boolean { - warn( - `hasStyle() has been deprecated and will be removed ` + - `in version 1.0.0. Use wrapper.element.style ` + - `instead` - ) - - if (typeof style !== 'string') { - throwError(`wrapper.hasStyle() must be passed style as a string`) - } - - if (typeof value !== 'string') { - throwError('wrapper.hasClass() must be passed value as string') - } - - /* istanbul ignore next */ - if ( - navigator.userAgent.includes && - (navigator.userAgent.includes('node.js') || - navigator.userAgent.includes('jsdom')) - ) { - warn( - `wrapper.hasStyle is not fully supported when ` + - `running jsdom - only inline styles are supported` - ) - } - const body = document.querySelector('body') - const mockElement = document.createElement('div') - - if (!(body instanceof Element)) { - return false - } - const mockNode = body.insertBefore(mockElement, null) - // $FlowIgnore : Flow thinks style[style] returns a number - mockElement.style[style] = value - - if (!this.options.attachedToDocument && (this.vm || this.vnode)) { - // $FlowIgnore : Possible null value, will be removed in 1.0.0 - const vm = this.vm || this.vnode.context.$root - body.insertBefore(vm.$root._vnode.elm, null) - } - - const elStyle = window.getComputedStyle(this.element)[style] - const mockNodeStyle = window.getComputedStyle(mockNode)[style] - return !!(elStyle && mockNodeStyle && elStyle === mockNodeStyle) - } - /** * Returns HTML of element as a string */ @@ -562,79 +429,6 @@ export default class Wrapper implements BaseWrapper { throwError(`wrapper.setSelected() cannot be called on this element`) } - /** - * Sets vm computed - */ - setComputed (computed: Object): void { - if (!this.isVueInstance()) { - throwError( - `wrapper.setComputed() can only be called on a Vue ` + - `instance` - ) - } - - warn( - `setComputed() has been deprecated and will be ` + - `removed in version 1.0.0. You can overwrite ` + - `computed properties by passing a computed object ` + - `in the mounting options` - ) - - Object.keys(computed).forEach(key => { - if (VUE_VERSION > 2.1) { - // $FlowIgnore : Problem with possibly null this.vm - if (!this.vm._computedWatchers[key]) { - throwError( - `wrapper.setComputed() was passed a value that ` + - `does not exist as a computed property on the ` + - `Vue instance. Property ${key} does not exist ` + - `on the Vue instance` - ) - } - // $FlowIgnore : Problem with possibly null this.vm - this.vm._computedWatchers[key].value = computed[key] - // $FlowIgnore : Problem with possibly null this.vm - this.vm._computedWatchers[key].getter = () => computed[key] - } else { - let isStore = false - // $FlowIgnore : Problem with possibly null this.vm - this.vm._watchers.forEach(watcher => { - if (watcher.getter.vuex && key in watcher.vm.$options.store.getters) { - watcher.vm.$options.store.getters = { - ...watcher.vm.$options.store.getters - } - Object.defineProperty(watcher.vm.$options.store.getters, key, { - get: function () { - return computed[key] - } - }) - isStore = true - } - }) - - // $FlowIgnore : Problem with possibly null this.vm - if (!isStore && !this.vm._watchers.some(w => w.getter.name === key)) { - throwError( - `wrapper.setComputed() was passed a value that does ` + - `not exist as a computed property on the Vue instance. ` + - `Property ${key} does not exist on the Vue instance` - ) - } - // $FlowIgnore : Problem with possibly null this.vm - this.vm._watchers.forEach(watcher => { - if (watcher.getter.name === key) { - watcher.value = computed[key] - watcher.getter = () => computed[key] - } - }) - } - }) - // $FlowIgnore : Problem with possibly null this.vm - this.vm._watchers.forEach(watcher => { - watcher.run() - }) - } - /** * Sets vm data */ @@ -830,28 +624,4 @@ export default class Wrapper implements BaseWrapper { `updates are now synchronous by default` ) } - - /** - * Utility to check wrapper is visible. Returns false if a parent - * element has display: none or visibility: hidden style. - */ - visible (): boolean { - warn( - `visible has been deprecated and will be removed in ` + - `version 1, use isVisible instead` - ) - let element = this.element - while (element) { - if ( - element.style && - (element.style.visibility === 'hidden' || - element.style.display === 'none') - ) { - return false - } - element = element.parentElement - } - - return true - } } diff --git a/packages/test-utils/types/index.d.ts b/packages/test-utils/types/index.d.ts index 43cc3ff04..c614b249d 100644 --- a/packages/test-utils/types/index.d.ts +++ b/packages/test-utils/types/index.d.ts @@ -53,7 +53,6 @@ interface BaseWrapper { contains (selector: Selector): boolean exists (): boolean isVisible (): boolean - visible (): boolean attributes(): { [name: string]: string } attributes(key: string): string | void @@ -62,16 +61,10 @@ interface BaseWrapper { props(): { [name: string]: any } props(key: string): any | void - hasAttribute (attribute: string, value: string): boolean - hasClass (className: string): boolean - hasProp (prop: string, value: any): boolean - hasStyle (style: string, value: string): boolean - is (selector: Selector): boolean isEmpty (): boolean isVueInstance (): boolean - setComputed (computed: object): void setData (data: object): void setMethods (data: object): void setProps (props: object): void diff --git a/packages/test-utils/types/test/wrapper.ts b/packages/test-utils/types/test/wrapper.ts index c5f2607db..5168056f8 100644 --- a/packages/test-utils/types/test/wrapper.ts +++ b/packages/test-utils/types/test/wrapper.ts @@ -13,12 +13,8 @@ bool = wrapper.contains(ClassComponent) bool = wrapper.exists() -bool = wrapper.hasAttribute('foo', 'bar') bool = wrapper.attributes().foo === 'bar' -bool = wrapper.hasClass('foo-class') -bool = wrapper.hasProp('checked', true) bool = wrapper.props().checked -bool = wrapper.hasStyle('color', 'red') bool = wrapper.classes('foo') bool = wrapper.is(normalOptions) @@ -33,7 +29,6 @@ let o: string = wrapper.emitted('hello')[0] const emittedByOrder = wrapper.emittedByOrder() const name: string = emittedByOrder[0].name -wrapper.setComputed({computedProp: true}) wrapper.setData({ foo: 'bar' }) wrapper.setMethods({checked: true}) wrapper.setProps({ checked: true }) diff --git a/test/specs/components/TransitionStub.spec.js b/test/specs/components/TransitionStub.spec.js index a8331cba8..fa16cc0d0 100644 --- a/test/specs/components/TransitionStub.spec.js +++ b/test/specs/components/TransitionStub.spec.js @@ -43,11 +43,11 @@ describeWithShallowAndMount('TransitionStub', mountingMethod => { transition: TransitionStub } }) - expect(wrapper.find('nav').visible()).to.equal(false) + expect(wrapper.find('nav').isVisible()).to.equal(false) wrapper.find('button').trigger('click') - expect(wrapper.find('nav').visible()).to.equal(true) + expect(wrapper.find('nav').isVisible()).to.equal(true) wrapper.find('button').trigger('click') - expect(wrapper.find('nav').visible()).to.equal(false) + expect(wrapper.find('nav').isVisible()).to.equal(false) }) it('logs error when has multiple children', () => { diff --git a/test/specs/wrapper-array.spec.js b/test/specs/wrapper-array.spec.js index 8e816c020..3fdf7506b 100644 --- a/test/specs/wrapper-array.spec.js +++ b/test/specs/wrapper-array.spec.js @@ -49,10 +49,6 @@ describeWithShallowAndMount('WrapperArray', mountingMethod => { 'contains', 'emitted', 'emittedByOrder', - 'hasAttribute', - 'hasClass', - 'hasProp', - 'hasStyle', 'find', 'findAll', 'html', @@ -64,7 +60,6 @@ describeWithShallowAndMount('WrapperArray', mountingMethod => { 'name', 'props', 'setChecked', - 'setComputed', 'setMethods', 'setData', 'setProps', @@ -91,16 +86,11 @@ describeWithShallowAndMount('WrapperArray', mountingMethod => { [ 'at', 'contains', - 'hasAttribute', - 'hasClass', - 'hasProp', - 'hasStyle', 'is', 'isEmpty', 'isVisible', 'isVueInstance', 'setChecked', - 'setComputed', 'setMethods', 'setData', 'setProps', @@ -164,73 +154,6 @@ describeWithShallowAndMount('WrapperArray', mountingMethod => { expect(wrapperArray.contains()).to.equal(false) }) - it('hasAttribute returns true if every wrapper.hasAttribute() returns true', () => { - const attribute = 'attribute' - const value = 'value' - const hasAttribute = sinon.stub() - hasAttribute.withArgs(attribute, value).returns(true) - const wrapperArray = getWrapperArray([{ hasAttribute }, { hasAttribute }]) - expect(wrapperArray.hasAttribute(attribute, value)).to.equal(true) - }) - - it('hasAttribute returns false if not every wrapper.hasAttribute() returns true', () => { - const wrapperArray = getWrapperArray([ - { hasAttribute: () => true }, - { hasAttribute: () => false } - ]) - expect(wrapperArray.hasAttribute('attribute', 'value')).to.equal(false) - }) - - it('hasClass returns true if every wrapper.hasClass() returns true', () => { - const className = 'class' - const hasClass = sinon.stub() - hasClass.withArgs(className).returns(true) - const wrapperArray = getWrapperArray([{ hasClass }, { hasClass }]) - expect(wrapperArray.hasClass(className)).to.equal(true) - }) - - it('hasClass returns false if not every wrapper.hasClass() returns true', () => { - const wrapperArray = getWrapperArray([ - { hasClass: () => true }, - { hasClass: () => false } - ]) - expect(wrapperArray.hasClass('class')).to.equal(false) - }) - - it('hasProp returns true if every wrapper.hasProp() returns true', () => { - const prop = 'prop' - const value = 'value' - const hasProp = sinon.stub() - hasProp.withArgs(prop, value).returns(true) - const wrapperArray = getWrapperArray([{ hasProp }, { hasProp }]) - expect(wrapperArray.hasProp(prop, value)).to.equal(true) - }) - - it('hasProp returns false if not every wrapper.hasProp() returns true', () => { - const wrapperArray = getWrapperArray([ - { hasProp: () => true }, - { hasProp: () => false } - ]) - expect(wrapperArray.hasProp('prop', 'value')).to.equal(false) - }) - - it('hasStyle returns true if every wrapper.hasStyle() returns true', () => { - const style = 'style' - const value = 'value' - const hasStyle = sinon.stub() - hasStyle.withArgs(style, value).returns(true) - const wrapperArray = getWrapperArray([{ hasStyle }, { hasStyle }]) - expect(wrapperArray.hasStyle(style, value)).to.equal(true) - }) - - it('hasStyle returns false if not every wrapper.hasStyle() returns true', () => { - const wrapperArray = getWrapperArray([ - { hasStyle: () => true }, - { hasStyle: () => false } - ]) - expect(wrapperArray.hasStyle('style', 'value')).to.equal(false) - }) - it('is returns true if every wrapper.is() returns true', () => { const selector = 'selector' const is = sinon.stub() @@ -295,15 +218,6 @@ describeWithShallowAndMount('WrapperArray', mountingMethod => { expect(wrapperArray.isVueInstance()).to.equal(false) }) - it('setComputed calls setMethods on each wrapper', () => { - const setComputed = sinon.stub() - const computed = {} - const wrapperArray = getWrapperArray([{ setComputed }, { setComputed }]) - wrapperArray.setComputed(computed) - expect(setComputed.calledTwice).to.equal(true) - expect(setComputed.calledWith(computed)).to.equal(true) - }) - it('setMethods calls setMethods on each wrapper', () => { const setMethods = sinon.stub() const methods = {} diff --git a/test/specs/wrapper-array/at.spec.js b/test/specs/wrapper-array/at.spec.js index 104f66e4d..4fc014ab5 100644 --- a/test/specs/wrapper-array/at.spec.js +++ b/test/specs/wrapper-array/at.spec.js @@ -9,7 +9,7 @@ describeWithShallowAndMount('at', mountingMethod => { .findAll('p') .at(1) expect(p.vnode).to.be.an('object') - expect(p.hasClass('index-1')).to.equal(true) + expect(p.classes()).to.contain('index-1') }) it('throws error if no item exists at index', () => { diff --git a/test/specs/wrapper-array/hasAttribute.spec.js b/test/specs/wrapper-array/hasAttribute.spec.js deleted file mode 100644 index 1ac0429ce..000000000 --- a/test/specs/wrapper-array/hasAttribute.spec.js +++ /dev/null @@ -1,61 +0,0 @@ -import { describeWithShallowAndMount } from '~resources/utils' -import { compileToFunctions } from 'vue-template-compiler' -import '~vue/test-utils' - -describeWithShallowAndMount('hasAttribute', mountingMethod => { - it('returns true if every item contains attribute matching value', () => { - const attribute = 'attribute' - const value = 'value' - const compiled = compileToFunctions( - `
` - ) - const wrapper = mountingMethod(compiled) - expect(wrapper.findAll('div').hasAttribute(attribute, value)).to.equal( - true - ) - }) - - it('returns false if every item does not contain attribute', () => { - const compiled = compileToFunctions('
') - const wrapper = mountingMethod(compiled) - expect(wrapper.findAll('div').hasAttribute('attribute', 'value')).to.equal( - false - ) - }) - - it('throws an error if attribute is not a string', () => { - const compiled = compileToFunctions('
') - const wrapper = mountingMethod(compiled) - const message = - '[vue-test-utils]: wrapper.hasAttribute() must be passed attribute as a string' - const fn = () => wrapper.findAll('div').hasAttribute(undefined, 'value') - expect(fn) - .to.throw() - .with.property('message', message) - }) - - it('throws error if wrapper array contains no items', () => { - const compiled = compileToFunctions('
') - const message = - '[vue-test-utils]: hasAttribute cannot be called on 0 items' - const fn = () => - mountingMethod(compiled) - .findAll('p') - .hasAttribute('p') - expect(fn) - .to.throw() - .with.property('message', message) - }) - - it('throws an error if value is not a string', () => { - const compiled = compileToFunctions('
') - const wrapper = mountingMethod(compiled) - const message = - '[vue-test-utils]: wrapper.hasAttribute() must be passed value as a string' - const fn = () => - wrapper.findAll('div').hasAttribute('attribute', undefined) - expect(fn) - .to.throw() - .with.property('message', message) - }) -}) diff --git a/test/specs/wrapper-array/hasClass.spec.js b/test/specs/wrapper-array/hasClass.spec.js deleted file mode 100644 index ebb911986..000000000 --- a/test/specs/wrapper-array/hasClass.spec.js +++ /dev/null @@ -1,54 +0,0 @@ -import { describeWithShallowAndMount } from '~resources/utils' -import { compileToFunctions } from 'vue-template-compiler' -import '~vue/test-utils' - -describeWithShallowAndMount('hasClass', mountingMethod => { - it('returns true if every item has class name', () => { - const compiled = compileToFunctions('
') - const wrapper = mountingMethod(compiled) - expect(wrapper.findAll('div').hasClass('a-class')).to.equal(true) - }) - - it('returns false if every item does not have class name', () => { - const compiled = compileToFunctions('
') - const wrapper = mountingMethod(compiled) - expect(wrapper.findAll('div').hasClass('not-class-name')).to.equal(false) - }) - - it('throws error if wrapper array contains no items', () => { - const compiled = compileToFunctions('
') - const message = '[vue-test-utils]: hasClass cannot be called on 0 items' - expect(() => - mountingMethod(compiled) - .findAll('p') - .hasClass('p') - ) - .to.throw() - .with.property('message', message) - }) - - it('throws error if selector is not a string', () => { - const compiled = compileToFunctions('
') - const wrapper = mountingMethod(compiled) - const invalidSelectors = [ - undefined, - null, - NaN, - 0, - 2, - true, - false, - () => {}, - {}, - [] - ] - invalidSelectors.forEach(invalidSelector => { - const message = - '[vue-test-utils]: wrapper.hasClass() must be passed a string' - const fn = () => wrapper.hasClass(invalidSelector) - expect(fn) - .to.throw() - .with.property('message', message) - }) - }) -}) diff --git a/test/specs/wrapper-array/hasProp.spec.js b/test/specs/wrapper-array/hasProp.spec.js deleted file mode 100644 index 94daafb23..000000000 --- a/test/specs/wrapper-array/hasProp.spec.js +++ /dev/null @@ -1,62 +0,0 @@ -import { compileToFunctions } from 'vue-template-compiler' -import ComponentWithChild from '~resources/components/component-with-child.vue' -import Component from '~resources/components/component.vue' -import { describeWithShallowAndMount } from '~resources/utils' - -describeWithShallowAndMount('hasProp', mountingMethod => { - it('returns false if every item does not have prop', () => { - const wrapper = mountingMethod(ComponentWithChild) - expect(wrapper.findAll(Component).hasProp('no-prop', 'value')).to.equal( - false - ) - }) - - it('throws error if items are not Vue components', () => { - const compiled = compileToFunctions('

') - const p = mountingMethod(compiled) - .findAll('p') - .at(0) - const message = - '[vue-test-utils]: wrapper.hasProp() must be called on a Vue instance' - expect(() => p.hasProp('no-prop', 'value')) - .to.throw() - .with.property('message', message) - }) - - it('throws error if wrapper array contains no items', () => { - const compiled = compileToFunctions('
') - const message = '[vue-test-utils]: hasProp cannot be called on 0 items' - expect(() => - mountingMethod(compiled) - .findAll('p') - .hasProp('p') - ) - .to.throw() - .with.property('message', message) - }) - - it('throws error if prop is not a string', () => { - const wrapper = mountingMethod(ComponentWithChild) - const invalidSelectors = [ - undefined, - null, - NaN, - 0, - 2, - true, - false, - () => {}, - {}, - [] - ] - invalidSelectors.forEach(invalidSelector => { - const message = - '[vue-test-utils]: wrapper.hasProp() must be passed prop as a string' - const fn = () => - wrapper.find(Component).hasProp(invalidSelector, 'value') - expect(fn) - .to.throw() - .with.property('message', message) - }) - }) -}) diff --git a/test/specs/wrapper-array/hasStyle.spec.js b/test/specs/wrapper-array/hasStyle.spec.js deleted file mode 100644 index 12ec64039..000000000 --- a/test/specs/wrapper-array/hasStyle.spec.js +++ /dev/null @@ -1,77 +0,0 @@ -import { compileToFunctions } from 'vue-template-compiler' -import ComponentWithStyle from '~resources/components/component-with-style.vue' -import { describeWithShallowAndMount } from '~resources/utils' - -describeWithShallowAndMount('hasStyle', mountingMethod => { - it('returns true if every item contains styles, set inline', () => { - const compiled = compileToFunctions( - '
' - ) - const wrapper = mountingMethod(compiled) - expect(wrapper.findAll('div').hasStyle('color', 'red')).to.equal(true) - }) - - it('returns true if every item contains style, set in stylesheet', () => { - if (navigator.userAgent.includes && navigator.userAgent.includes('jsdom')) { - return - } - const wrapper = mountingMethod(ComponentWithStyle) - expect(wrapper.findAll('div').hasStyle('color', 'red')).to.equal(true) - }) - - it('returns true if every item contains styles, set in stylesheet with multiple selectors when not attached to document', () => { - if (navigator.userAgent.includes && navigator.userAgent.includes('jsdom')) { - return - } - const wrapper = mountingMethod(ComponentWithStyle) - expect(wrapper.findAll('p').hasStyle('color', 'red')).to.equal(true) - expect(wrapper.findAll('span').hasStyle('color', 'red')).to.equal(true) - expect(wrapper.findAll('span').hasStyle('color', 'orange')).to.equal(false) - }) - - it('returns true if every item contains styles, set in stylesheet with multiple selectors when attached to document', () => { - if (navigator.userAgent.includes && navigator.userAgent.includes('jsdom')) { - return - } - const wrapper = mountingMethod(ComponentWithStyle, { - attachToDocument: true - }) - expect(wrapper.findAll('p').hasStyle('color', 'red')).to.equal(true) - expect(wrapper.findAll('span').hasStyle('color', 'red')).to.equal(true) - expect(wrapper.findAll('span').hasStyle('color', 'orange')).to.equal(false) - }) - - it('throws error if wrapper array contains no items', () => { - const compiled = compileToFunctions('
') - const message = '[vue-test-utils]: hasStyle cannot be called on 0 items' - const fn = () => - mountingMethod(compiled) - .findAll('p') - .hasStyle('p') - expect(fn) - .to.throw() - .with.property('message', message) - }) - - it('throws error if style is not a string', () => { - const compiled = compileToFunctions('
') - const wrapper = mountingMethod(compiled) - const message = - '[vue-test-utils]: wrapper.hasStyle() must be passed style as a string' - const fn = () => wrapper.findAll('div').hasStyle(undefined, 'red') - expect(fn) - .to.throw() - .with.property('message', message) - }) - - it('throws error if value is not a string', () => { - const compiled = compileToFunctions('
') - const wrapper = mountingMethod(compiled) - const message = - '[vue-test-utils]: wrapper.hasClass() must be passed value as string' - const fn = () => wrapper.findAll('div').hasStyle('color', undefined) - expect(fn) - .to.throw() - .with.property('message', message) - }) -}) diff --git a/test/specs/wrapper-array/trigger.spec.js b/test/specs/wrapper-array/trigger.spec.js index cc27da5cc..90b050f61 100644 --- a/test/specs/wrapper-array/trigger.spec.js +++ b/test/specs/wrapper-array/trigger.spec.js @@ -34,14 +34,6 @@ describeWithShallowAndMount('trigger', mountingMethod => { expect(keydownHandler.calledOnce).to.equal(true) }) - it('causes DOM to update after clickHandler method that changes components data is called', () => { - const wrapper = mountingMethod(ComponentWithEvents) - const toggleArr = wrapper.findAll('.toggle') - expect(toggleArr.hasClass('active')).to.equal(false) - toggleArr.trigger('click') - expect(toggleArr.hasClass('active')).to.equal(true) - }) - it('throws an error if type is not a string', () => { const wrapper = mountingMethod(ComponentWithEvents) const invalidSelectors = [ diff --git a/test/specs/wrapper/hasAttribute.spec.js b/test/specs/wrapper/hasAttribute.spec.js deleted file mode 100644 index 416a7780b..000000000 --- a/test/specs/wrapper/hasAttribute.spec.js +++ /dev/null @@ -1,40 +0,0 @@ -import { compileToFunctions } from 'vue-template-compiler' -import { describeWithShallowAndMount } from '~resources/utils' - -describeWithShallowAndMount('hasAttribute', mountingMethod => { - it('returns true if wrapper contains attribute matching value', () => { - const attribute = 'attribute' - const value = 'value' - const compiled = compileToFunctions(`
`) - const wrapper = mountingMethod(compiled) - expect(wrapper.hasAttribute(attribute, value)).to.equal(true) - }) - - it('returns false if wrapper does not contain attribute', () => { - const compiled = compileToFunctions('
') - const wrapper = mountingMethod(compiled) - expect(wrapper.hasAttribute('attribute', 'value')).to.equal(false) - }) - - it('throws an error if attribute is not a string', () => { - const compiled = compileToFunctions('
') - const wrapper = mountingMethod(compiled) - const message = - '[vue-test-utils]: wrapper.hasAttribute() must be passed attribute as a string' - const fn = () => wrapper.hasAttribute(undefined, 'value') - expect(fn) - .to.throw() - .with.property('message', message) - }) - - it('throws an error if value is not a string', () => { - const compiled = compileToFunctions('
') - const wrapper = mountingMethod(compiled) - const message = - '[vue-test-utils]: wrapper.hasAttribute() must be passed value as a string' - const fn = () => wrapper.hasAttribute('attribute', undefined) - expect(fn) - .to.throw() - .with.property('message', message) - }) -}) diff --git a/test/specs/wrapper/hasClass.spec.js b/test/specs/wrapper/hasClass.spec.js deleted file mode 100644 index b149f013d..000000000 --- a/test/specs/wrapper/hasClass.spec.js +++ /dev/null @@ -1,60 +0,0 @@ -import ComponentWithCssModules from '~resources/components/component-with-css-modules.vue' -import { compileToFunctions } from 'vue-template-compiler' -import { describeWithShallowAndMount } from '~resources/utils' - -describeWithShallowAndMount('hasClass', mountingMethod => { - it('returns true if wrapper has class name', () => { - const compiled = compileToFunctions('
') - const wrapper = mountingMethod(compiled) - expect(wrapper.hasClass('a-class')).to.equal(true) - }) - - it('returns false if wrapper does not have class name', () => { - const compiled = compileToFunctions('
') - const wrapper = mountingMethod(compiled) - expect(wrapper.hasClass('not-class-name')).to.equal(false) - }) - - it('returns false if wrapper includes class name in string, but not as a seperate class', () => { - const compiled = compileToFunctions('
') - const wrapper = mountingMethod(compiled) - expect(wrapper.hasClass('class-name')).to.equal(false) - }) - - it('throws an error if selector is not a string', () => { - const compiled = compileToFunctions('
') - const wrapper = mountingMethod(compiled) - const invalidSelectors = [ - undefined, - null, - NaN, - 0, - 2, - true, - false, - () => {}, - {}, - [] - ] - invalidSelectors.forEach(invalidSelector => { - const message = - '[vue-test-utils]: wrapper.hasClass() must be passed a string' - const fn = () => wrapper.hasClass(invalidSelector) - expect(fn) - .to.throw() - .with.property('message', message) - }) - }) - - it('returns true when element contains class name mapped in css modules', () => { - const wrapper = mountingMethod(ComponentWithCssModules) - - expect(wrapper.hasClass('color-red')).to.equal(true) - }) - - it('returns true when the element contains multiple classes', () => { - const compiled = compileToFunctions('
') - const wrapper = mountingMethod(compiled) - expect(wrapper.hasClass('a-class b-class')).to.equal(true) - }) -}) diff --git a/test/specs/wrapper/hasProp.spec.js b/test/specs/wrapper/hasProp.spec.js deleted file mode 100644 index 77c70d44e..000000000 --- a/test/specs/wrapper/hasProp.spec.js +++ /dev/null @@ -1,58 +0,0 @@ -import { compileToFunctions } from 'vue-template-compiler' -import ComponentWithProps from '~resources/components/component-with-props.vue' -import { describeWithShallowAndMount } from '~resources/utils' - -describeWithShallowAndMount('hasProp', mountingMethod => { - it('returns true if wrapper has prop', () => { - const prop1 = {} - const prop2 = 'a prop' - const wrapper = mountingMethod(ComponentWithProps, { - propsData: { prop1, prop2 } - }) - expect(wrapper.hasProp('a-class')).to.equal(true) - }) - - it('returns false if wrapper does not have class name', () => { - const compiled = compileToFunctions('
') - const wrapper = mountingMethod(compiled) - expect(wrapper.hasProp('no-prop', 'value')).to.equal(false) - }) - - it('throws an error if called on a non vm wrapper', () => { - const compiled = compileToFunctions('

') - const p = mountingMethod(compiled) - .findAll('p') - .at(0) - const message = - '[vue-test-utils]: wrapper.hasProp() must be called on a Vue instance' - const fn = () => p.hasProp('no-prop', 'value') - expect(fn) - .to.throw() - .with.property('message', message) - }) - - it('throws an error if prop is not a string', () => { - const compiled = compileToFunctions('
') - const wrapper = mountingMethod(compiled) - const invalidSelectors = [ - undefined, - null, - NaN, - 0, - 2, - true, - false, - () => {}, - {}, - [] - ] - invalidSelectors.forEach(invalidSelector => { - const message = - '[vue-test-utils]: wrapper.hasProp() must be passed prop as a string' - const fn = () => wrapper.hasProp(invalidSelector, 'value') - expect(fn) - .to.throw() - .with.property('message', message) - }) - }) -}) diff --git a/test/specs/wrapper/hasStyle.spec.js b/test/specs/wrapper/hasStyle.spec.js deleted file mode 100644 index 8188550f5..000000000 --- a/test/specs/wrapper/hasStyle.spec.js +++ /dev/null @@ -1,71 +0,0 @@ -import { compileToFunctions } from 'vue-template-compiler' -import ComponentWithStyle from '~resources/components/component-with-style.vue' -import { describeWithShallowAndMount } from '~resources/utils' - -describeWithShallowAndMount('hasStyle', mountingMethod => { - it('returns true when element contains styles, set inline', () => { - const compiled = compileToFunctions('
') - const wrapper = mountingMethod(compiled) - expect(wrapper.find('div').hasStyle('color', 'red')).to.equal(true) - }) - - it('returns true when element contains styles, set in stylesheet', () => { - if (navigator.userAgent.includes && navigator.userAgent.includes('jsdom')) { - return - } - const wrapper = mountingMethod(ComponentWithStyle) - expect(wrapper.find('div').hasStyle('color', 'red')).to.equal(true) - }) - - it('returns true when element contains styles, set in stylesheet with multiple selectors when not attached to document', () => { - if (navigator.userAgent.includes && navigator.userAgent.includes('jsdom')) { - return - } - const wrapper = mountingMethod(ComponentWithStyle) - expect(wrapper.find('p').hasStyle('color', 'red')).to.equal(true) - expect(wrapper.find('span').hasStyle('color', 'red')).to.equal(true) - expect(wrapper.find('span').hasStyle('color', 'orange')).to.equal(false) - }) - - it('returns true when element contains styles, set in stylesheet with multiple selectors when attached to document', () => { - if (navigator.userAgent.includes && navigator.userAgent.includes('jsdom')) { - return - } - const wrapper = mountingMethod(ComponentWithStyle, { - attachToDocument: true - }) - expect(wrapper.find('p').hasStyle('color', 'red')).to.equal(true) - expect(wrapper.find('span').hasStyle('color', 'red')).to.equal(true) - expect(wrapper.find('span').hasStyle('color', 'orange')).to.equal(false) - }) - - it('throws an error if style is not a string', () => { - const compiled = compileToFunctions('
') - const wrapper = mountingMethod(compiled) - const message = - '[vue-test-utils]: wrapper.hasStyle() must be passed style as a string' - const fn = () => wrapper.hasStyle(undefined, 'red') - expect(fn) - .to.throw() - .with.property('message', message) - }) - - it('throws an error if value is not a string', () => { - const compiled = compileToFunctions('
') - const wrapper = mountingMethod(compiled) - const message = - '[vue-test-utils]: wrapper.hasClass() must be passed value as string' - const fn = () => wrapper.hasStyle('color', undefined) - expect(fn) - .to.throw() - .with.property('message', message) - }) - - it('return false when the style is a invalid prop name ', () => { - if (navigator.userAgent.includes && navigator.userAgent.includes('jsdom')) { - return - } - const wrapper = mountingMethod(ComponentWithStyle) - expect(wrapper.find('p').hasStyle('margin-top333', '10px')).to.equal(false) - }) -}) diff --git a/test/specs/wrapper/setComputed.spec.js b/test/specs/wrapper/setComputed.spec.js deleted file mode 100644 index 6744234e3..000000000 --- a/test/specs/wrapper/setComputed.spec.js +++ /dev/null @@ -1,93 +0,0 @@ -import { compileToFunctions } from 'vue-template-compiler' -import { createLocalVue } from '~vue/test-utils' -import Vuex, { mapGetters } from 'vuex' -import ComponentWithComputed from '~resources/components/component-with-computed.vue' -import ComponentWithWatch from '~resources/components/component-with-watch.vue' -import { describeWithShallowAndMount } from '~resources/utils' - -describeWithShallowAndMount('setComputed', mountingMethod => { - let info - - beforeEach(() => { - info = sinon.stub(console, 'info') - }) - - afterEach(() => { - info.restore() - }) - - it('sets component computed props and updates when called on Vue instance', () => { - const wrapper = mountingMethod(ComponentWithComputed) - expect(wrapper.text()).to.contain('message') - wrapper.setComputed({ reversedMessage: 'custom' }) - expect(wrapper.text()).to.contain('custom') - }) - - it('throws an error if computed watcher does not exist', () => { - const message = - 'wrapper.setComputed() was passed a value that does not exist as a computed property on the Vue instance. Property noExist does not exist on the Vue instance' - const wrapper = mountingMethod(ComponentWithComputed) - expect(() => wrapper.setComputed({ noExist: '' })).throw(Error, message) - }) - - it('runs watch function after all props are updated', () => { - const wrapper = mountingMethod(ComponentWithWatch) - const computed1 = 'new computed' - wrapper.setComputed({ computed1 }) - expect(info.args[0][0]).to.equal(computed1) - expect(wrapper.vm.computed1).to.equal(computed1) - }) - - it('updates vm computed value', () => { - const TestComponent = { - render: () => {}, - data () { - return { - a: 1 - } - }, - computed: { - b () { - return this.a * 2 - } - } - } - - const wrapper = mountingMethod(TestComponent) - wrapper.setComputed({ b: 3 }) - expect(wrapper.vm.b).to.equal(3) - }) - - it('works correctly with mapGetters', () => { - const localVue = createLocalVue() - localVue.use(Vuex) - const store = new Vuex.Store({ - getters: { - someGetter: () => false - } - }) - const TestComponent = { - computed: { - ...mapGetters(['someGetter']), - placeholder () { - return this.someGetter ? 'someGetter is true' : 'someGetter is false' - } - } - } - const wrapper = mountingMethod(TestComponent, { - localVue, - store - }) - wrapper.setComputed({ someGetter: true }) - expect(wrapper.vm.placeholder).to.equal('someGetter is true') - }) - - it('throws an error if node is not a Vue instance', () => { - const message = - 'wrapper.setComputed() can only be called on a Vue instance' - const compiled = compileToFunctions('

') - const wrapper = mountingMethod(compiled) - const p = wrapper.find('p') - expect(() => p.setComputed({ ready: true })).throw(Error, message) - }) -})