From 2872a201e7ba3dced329177b5a95958de5440540 Mon Sep 17 00:00:00 2001 From: Edd Yerburgh Date: Fri, 15 Jun 2018 17:59:50 +0100 Subject: [PATCH] refactor: add max-len rule (#720) --- .eslintrc | 5 +- docs/api/options.md | 4 +- docs/api/wrapper-array/filter.md | 3 +- docs/guides/common-tips.md | 6 +- docs/guides/using-with-vuex.md | 4 +- docs/ja/api/options.md | 4 +- docs/ja/api/wrapper-array/filter.md | 3 +- docs/ja/guides/using-with-vuex.md | 4 +- docs/zh/api/options.md | 4 +- docs/zh/api/wrapper-array/filter.md | 3 +- flow/options.flow.js | 37 +- flow/vue.flow.js | 4 +- flow/wrapper.flow.js | 80 +-- packages/create-instance/add-mocks.js | 8 +- packages/create-instance/add-slots.js | 8 +- .../create-functional-component.js | 20 +- packages/create-instance/create-instance.js | 58 +- packages/create-instance/log-events.js | 6 +- packages/create-instance/validate-slots.js | 27 +- packages/server-test-utils/scripts/build.js | 4 +- packages/server-test-utils/src/render.js | 5 +- .../server-test-utils/src/renderToString.js | 11 +- packages/shared/compile-template.js | 2 +- packages/shared/merge-options.js | 15 +- packages/shared/stub-components.js | 43 +- packages/shared/util.js | 15 +- packages/shared/validators.js | 32 +- packages/test-utils/scripts/build.js | 4 +- packages/test-utils/src/add-scoped-slots.js | 47 +- .../src/components/TransitionStub.js | 14 +- packages/test-utils/src/consts.js | 7 +- packages/test-utils/src/create-local-vue.js | 5 +- packages/test-utils/src/error-handler.js | 7 +- packages/test-utils/src/error-wrapper.js | 187 +++++-- packages/test-utils/src/find-vnodes.js | 33 +- .../test-utils/src/find-vue-components.js | 59 +- packages/test-utils/src/find.js | 19 +- packages/test-utils/src/get-selector-type.js | 14 +- packages/test-utils/src/index.js | 5 +- packages/test-utils/src/matches-polyfill.js | 22 +- packages/test-utils/src/mount.js | 15 +- packages/test-utils/src/order-watchers.js | 2 +- .../test-utils/src/set-watchers-to-sync.js | 4 +- packages/test-utils/src/shallow-mount.js | 5 +- packages/test-utils/src/vue-wrapper.js | 10 +- packages/test-utils/src/warn-if-no-window.js | 12 +- packages/test-utils/src/wrapper-array.js | 69 ++- packages/test-utils/src/wrapper.js | 369 ++++++++---- scripts/gen-release-note.js | 6 +- test/resources/test-mixin.js | 3 +- test/resources/utils.js | 14 +- test/setup/webpack.test.config.js | 6 +- test/specs/.eslintrc | 3 + test/specs/components/RouterLink.spec.js | 2 +- .../components/TransitionGroupStub.spec.js | 2 +- test/specs/components/TransitionStub.spec.js | 13 +- test/specs/config.spec.js | 50 +- test/specs/create-local-vue.spec.js | 12 +- test/specs/error-wrapper.spec.js | 40 +- test/specs/mount.spec.js | 527 +++++++++--------- .../mounting-options/attachToDocument.spec.js | 14 +- test/specs/mounting-options/attrs.spec.js | 26 +- test/specs/mounting-options/context.spec.js | 32 +- test/specs/mounting-options/listeners.spec.js | 36 +- test/specs/mounting-options/localVue.spec.js | 79 ++- test/specs/mounting-options/methods.spec.js | 11 +- test/specs/mounting-options/mocks.spec.js | 151 ++--- test/specs/mounting-options/propsData.spec.js | 37 +- test/specs/mounting-options/provide.spec.js | 90 +-- .../mounting-options/scopedSlots.spec.js | 90 ++- test/specs/mounting-options/slots.spec.js | 315 +++++++---- test/specs/mounting-options/stubs.spec.js | 226 ++++---- test/specs/mounting-options/sync.spec.js | 4 +- test/specs/renderToString.spec.js | 14 +- test/specs/shallow-mount.spec.js | 351 ++++++------ test/specs/wrapper-array.spec.js | 137 ++++- test/specs/wrapper-array/at.spec.js | 14 +- test/specs/wrapper-array/attributes.spec.js | 17 +- test/specs/wrapper-array/classes.spec.js | 17 +- test/specs/wrapper-array/contains.spec.js | 39 +- test/specs/wrapper-array/find.spec.js | 21 +- test/specs/wrapper-array/findAll.spec.js | 21 +- test/specs/wrapper-array/hasAttribute.spec.js | 43 +- test/specs/wrapper-array/hasClass.spec.js | 30 +- test/specs/wrapper-array/hasProp.spec.js | 48 +- test/specs/wrapper-array/hasStyle.spec.js | 33 +- test/specs/wrapper-array/html.spec.js | 17 +- test/specs/wrapper-array/is.spec.js | 36 +- test/specs/wrapper-array/isEmpty.spec.js | 11 +- test/specs/wrapper-array/isVisible.spec.js | 19 +- .../specs/wrapper-array/isVueInstance.spec.js | 14 +- test/specs/wrapper-array/name.spec.js | 18 +- test/specs/wrapper-array/props.spec.js | 17 +- test/specs/wrapper-array/setData.spec.js | 18 +- test/specs/wrapper-array/setProps.spec.js | 18 +- test/specs/wrapper-array/text.spec.js | 18 +- test/specs/wrapper-array/trigger.spec.js | 31 +- test/specs/wrapper/at.spec.js | 6 +- test/specs/wrapper/attributes.spec.js | 2 +- test/specs/wrapper/classes.spec.js | 6 +- test/specs/wrapper/contains.spec.js | 37 +- test/specs/wrapper/destroy.spec.js | 2 +- test/specs/wrapper/emitted.spec.js | 41 +- test/specs/wrapper/emittedByOrder.spec.js | 9 +- test/specs/wrapper/exists.spec.js | 2 +- test/specs/wrapper/filter.spec.js | 9 +- test/specs/wrapper/find.spec.js | 121 ++-- test/specs/wrapper/findAll.spec.js | 83 ++- test/specs/wrapper/hasAttribute.spec.js | 16 +- test/specs/wrapper/hasClass.spec.js | 22 +- test/specs/wrapper/hasProp.spec.js | 33 +- test/specs/wrapper/hasStyle.spec.js | 20 +- test/specs/wrapper/html.spec.js | 5 +- test/specs/wrapper/is.spec.js | 36 +- test/specs/wrapper/isEmpty.spec.js | 28 +- test/specs/wrapper/isVisible.spec.js | 14 +- test/specs/wrapper/isVueInstance.spec.js | 2 +- test/specs/wrapper/name.spec.js | 2 +- test/specs/wrapper/props.spec.js | 29 +- test/specs/wrapper/setChecked.spec.js | 24 +- test/specs/wrapper/setComputed.spec.js | 16 +- test/specs/wrapper/setData.spec.js | 31 +- test/specs/wrapper/setMethods.spec.js | 2 +- test/specs/wrapper/setProps.spec.js | 38 +- test/specs/wrapper/setSelected.spec.js | 24 +- test/specs/wrapper/setValue.spec.js | 24 +- test/specs/wrapper/text.spec.js | 11 +- test/specs/wrapper/trigger.spec.js | 53 +- 128 files changed, 3096 insertions(+), 1767 deletions(-) diff --git a/.eslintrc b/.eslintrc index 069c07d70..1946f1b63 100644 --- a/.eslintrc +++ b/.eslintrc @@ -12,8 +12,9 @@ "plugin:vue-libs/recommended", "plugin:flowtype/recommended" ], - rules: { + "rules": { "no-debugger": 2, - "no-proto": 0 + "no-proto": 0, + "max-len": 2 } } diff --git a/docs/api/options.md b/docs/api/options.md index 572e77273..b636aac81 100644 --- a/docs/api/options.md +++ b/docs/api/options.md @@ -82,7 +82,9 @@ const wrapper = shallowMount(Component, { foo: '

{{props.index}},{{props.text}}

' } }) -expect(wrapper.find('#fooWrapper').html()).toBe('

0,text1

1,text2

2,text3

') +expect(wrapper.find('#fooWrapper').html()).toBe( + `

0,text1

1,text2

2,text3

` +) ``` ## stubs diff --git a/docs/api/wrapper-array/filter.md b/docs/api/wrapper-array/filter.md index ba8cb9004..941ec6713 100644 --- a/docs/api/wrapper-array/filter.md +++ b/docs/api/wrapper-array/filter.md @@ -18,5 +18,6 @@ import { shallowMount } from '@vue/test-utils' import Foo from './Foo.vue' const wrapper = shallowMount(Foo) -const filteredDivArray = wrapper.findAll('div').filter(w => !w.hasClass('filtered')) +const filteredDivArray = wrapper.findAll('div') + .filter(w => !w.hasClass('filtered')) ``` diff --git a/docs/guides/common-tips.md b/docs/guides/common-tips.md index 5ec7b92c2..64a5412bd 100644 --- a/docs/guides/common-tips.md +++ b/docs/guides/common-tips.md @@ -23,7 +23,7 @@ Vue Test Utils allows you to mount a component without rendering its child compo ```js import { shallowMount } from '@vue/test-utils' -const wrapper = shallowMount(Component) // returns a Wrapper containing a mounted Component instance +const wrapper = shallowMount(Component) wrapper.vm // the mounted Vue instance ``` @@ -125,7 +125,9 @@ const $route = { mount(Component, { mocks: { - $route // adds the mocked `$route` object to the Vue instance before mounting component + // adds mocked `$route` object to the Vue instance + // before mounting component + $route } }) ``` diff --git a/docs/guides/using-with-vuex.md b/docs/guides/using-with-vuex.md index af608040c..7fb25db82 100644 --- a/docs/guides/using-with-vuex.md +++ b/docs/guides/using-with-vuex.md @@ -69,7 +69,7 @@ describe('Actions.vue', () => { }) }) - it('calls store action "actionInput" when input value is "input" and an "input" event is fired', () => { + it('dispatches "actionInput" when input event value is "input"', () => { const wrapper = shallowMount(Actions, { store, localVue }) const input = wrapper.find('input') input.element.value = 'input' @@ -77,7 +77,7 @@ describe('Actions.vue', () => { expect(actions.actionInput).toHaveBeenCalled() }) - it('does not call store action "actionInput" when input value is not "input" and an "input" event is fired', () => { + it('does not dispatch "actionInput" when event value is not "input"', () => { const wrapper = shallowMount(Actions, { store, localVue }) const input = wrapper.find('input') input.element.value = 'not input' diff --git a/docs/ja/api/options.md b/docs/ja/api/options.md index c3cfef1d9..5230b9b22 100644 --- a/docs/ja/api/options.md +++ b/docs/ja/api/options.md @@ -77,7 +77,9 @@ const wrapper = shallowMount(Component, { foo: '

{{props.index}},{{props.text}}

' } }) -expect(wrapper.find('#fooWrapper').html()).toBe('

0,text1

1,text2

2,text3

') +expect(wrapper.find('#fooWrapper').html()).toBe( + `

0,text1

1,text2

2,text3

` +) ``` ## stubs diff --git a/docs/ja/api/wrapper-array/filter.md b/docs/ja/api/wrapper-array/filter.md index ea727d932..739ef055b 100644 --- a/docs/ja/api/wrapper-array/filter.md +++ b/docs/ja/api/wrapper-array/filter.md @@ -18,5 +18,6 @@ import { shallowMount } from '@vue/test-utils' import Foo from './Foo.vue' const wrapper = shallowMount(Foo) -const filteredDivArray = wrapper.findAll('div').filter(w => !w.hasClass('filtered')) +const filteredDivArray = wrapper.findAll('div') + .filter(w => !w.hasClass('filtered')) ``` diff --git a/docs/ja/guides/using-with-vuex.md b/docs/ja/guides/using-with-vuex.md index 53d684461..76d583fcd 100644 --- a/docs/ja/guides/using-with-vuex.md +++ b/docs/ja/guides/using-with-vuex.md @@ -68,7 +68,7 @@ describe('Actions.vue', () => { }) }) - it('calls store action actionInput when input value is input and an input event is fired', () => { + it('dispatches "actionInput" when input event value is "input"', () => { const wrapper = shallowMount(Actions, { store, localVue }) const input = wrapper.find('input') input.element.value = 'input' @@ -76,7 +76,7 @@ describe('Actions.vue', () => { expect(actions.actionInput).toHaveBeenCalled() }) - it('does not call store action actionInput when input value is not input and an input event is fired', () => { + it('does not dispatch "actionInput" when event value is not "input"', () => { const wrapper = shallowMount(Actions, { store, localVue }) const input = wrapper.find('input') input.element.value = 'not input' diff --git a/docs/zh/api/options.md b/docs/zh/api/options.md index 2365dcfab..72c210287 100644 --- a/docs/zh/api/options.md +++ b/docs/zh/api/options.md @@ -82,7 +82,9 @@ const wrapper = shallowMount(Component, { foo: '

{{props.index}},{{props.text}}

' } }) -expect(wrapper.find('#fooWrapper').html()).toBe('

0,text1

1,text2

2,text3

') +expect(wrapper.find('#fooWrapper').html()).toBe( + `

0,text1

1,text2

2,text3

` +) ``` ## stubs diff --git a/docs/zh/api/wrapper-array/filter.md b/docs/zh/api/wrapper-array/filter.md index 62e70ddfb..2857b7088 100644 --- a/docs/zh/api/wrapper-array/filter.md +++ b/docs/zh/api/wrapper-array/filter.md @@ -18,5 +18,6 @@ import { shallowMount } from '@vue/test-utils' import Foo from './Foo.vue' const wrapper = shallowMount(Foo) -const filteredDivArray = wrapper.findAll('div').filter(w => !w.hasClass('filtered')) +const filteredDivArray = wrapper.findAll('div') + .filter(w => !w.hasClass('filtered')) ``` diff --git a/flow/options.flow.js b/flow/options.flow.js index 0a8549919..618e47eed 100644 --- a/flow/options.flow.js +++ b/flow/options.flow.js @@ -1,20 +1,21 @@ -declare type Options = { // eslint-disable-line no-undef - attachToDocument?: boolean, - propsData?: Object, - mocks?: Object, - methods?: Object, - slots?: Object, - scopedSlots?: Object, - localVue?: Component, - provide?: Object, - stubs?: Object, - context?: Object, - attrs?: Object, - listeners?: Object, - logModifiedComponents?: boolean, - sync?: boolean -} +declare type Options = { + // eslint-disable-line no-undef + attachToDocument?: boolean, + propsData?: Object, + mocks?: Object, + methods?: Object, + slots?: Object, + scopedSlots?: Object, + localVue?: Component, + provide?: Object, + stubs?: Object, + context?: Object, + attrs?: Object, + listeners?: Object, + logModifiedComponents?: boolean, + sync?: boolean +}; -declare type SlotValue = Component | string | Array +declare type SlotValue = Component | string | Array; -declare type SlotsObject = {[name: string]: SlotValue} +declare type SlotsObject = { [name: string]: SlotValue }; diff --git a/flow/vue.flow.js b/flow/vue.flow.js index 7826aa089..013fe891b 100644 --- a/flow/vue.flow.js +++ b/flow/vue.flow.js @@ -2,5 +2,5 @@ // Importing these types declares them, so they are available globally -declare type Component = Object | Function // eslint-disable-line no-undef -declare type VNode = Object // eslint-disable-line no-undef +declare type Component = Object | Function; // eslint-disable-line no-undef +declare type VNode = Object; // eslint-disable-line no-undef diff --git a/flow/wrapper.flow.js b/flow/wrapper.flow.js index 218345ea0..75a22fe0a 100644 --- a/flow/wrapper.flow.js +++ b/flow/wrapper.flow.js @@ -3,44 +3,48 @@ import type Wrapper from '~src/Wrapper' import type WrapperArray from '~src/WrapperArray' -declare type Selector = any +declare type Selector = any; -declare interface BaseWrapper { // eslint-disable-line no-undef - at(index: number): Wrapper | void, - attributes(): { [name: string]: string } | void, - classes(): Array | void, - contains(selector: Selector): boolean | void, - emitted(event?: string): { [name: string]: Array> } | Array> | void, - 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, - is(selector: Selector): boolean | void, - isEmpty(): boolean | void, - isVisible(): boolean | void, - isVueInstance(): boolean | void, - name(): string | void, - props(): { [name: string]: 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, - setSelected(): void, - setProps(data: Object): void, - trigger(type: string, options: Object): void, - destroy(): void +declare interface BaseWrapper { + // eslint-disable-line no-undef + at(index: number): Wrapper | void; + attributes(): { [name: string]: string } | void; + classes(): Array | void; + contains(selector: Selector): boolean | void; + emitted( + event?: string + ): { [name: string]: Array> } | Array> | void; + 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; + is(selector: Selector): boolean | void; + isEmpty(): boolean | void; + isVisible(): boolean | void; + isVueInstance(): boolean | void; + name(): string | void; + props(): { [name: string]: 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; + setSelected(): void; + setProps(data: Object): void; + trigger(type: string, options: Object): void; + destroy(): void; } -declare type WrapperOptions = { // eslint-disable-line no-undef - attachedToDocument: boolean, - sync?: boolean -} +declare type WrapperOptions = { + // eslint-disable-line no-undef + attachedToDocument: boolean, + sync?: boolean +}; diff --git a/packages/create-instance/add-mocks.js b/packages/create-instance/add-mocks.js index 9263700cc..6da38579e 100644 --- a/packages/create-instance/add-mocks.js +++ b/packages/create-instance/add-mocks.js @@ -3,11 +3,15 @@ import $$Vue from 'vue' import { warn } from 'shared/util' export default function addMocks (mockedProperties: Object, Vue: Component) { - Object.keys(mockedProperties).forEach((key) => { + Object.keys(mockedProperties).forEach(key => { try { Vue.prototype[key] = mockedProperties[key] } catch (e) { - warn(`could not overwrite property ${key}, this usually caused by a plugin that has added the property as a read-only value`) + warn( + `could not overwrite property ${key}, this is ` + + `usually caused by a plugin that has added ` + + `the property as a read-only value` + ) } $$Vue.util.defineReactive(Vue, key, mockedProperties[key]) }) diff --git a/packages/create-instance/add-slots.js b/packages/create-instance/add-slots.js index 8bbc61ea0..746cae35b 100644 --- a/packages/create-instance/add-slots.js +++ b/packages/create-instance/add-slots.js @@ -11,14 +11,12 @@ function createVNodesForSlot ( slotValue: SlotValue, name: string ): VNode | string { - if (typeof slotValue === 'string' && - !startsWithTag(slotValue)) { + if (typeof slotValue === 'string' && !startsWithTag(slotValue)) { return slotValue } - const el = typeof slotValue === 'string' - ? compileToFunctions(slotValue) - : slotValue + const el = + typeof slotValue === 'string' ? compileToFunctions(slotValue) : slotValue const vnode = h(el) vnode.data.slot = name diff --git a/packages/create-instance/create-functional-component.js b/packages/create-instance/create-functional-component.js index 2d5eb2bba..ab83710c4 100644 --- a/packages/create-instance/create-functional-component.js +++ b/packages/create-instance/create-functional-component.js @@ -16,13 +16,17 @@ function createFunctionalSlots (slots = {}, h) { Object.keys(slots).forEach(slotType => { if (Array.isArray(slots[slotType])) { slots[slotType].forEach(slot => { - const component = typeof slot === 'string' ? compileToFunctions(slot) : slot + const component = + typeof slot === 'string' ? compileToFunctions(slot) : slot const newSlot = h(component) newSlot.data.slot = slotType children.push(newSlot) }) } else { - const component = typeof slots[slotType] === 'string' ? compileToFunctions(slots[slotType]) : slots[slotType] + const component = + typeof slots[slotType] === 'string' + ? compileToFunctions(slots[slotType]) + : slots[slotType] const slot = h(component) slot.data.slot = slotType children.push(slot) @@ -31,7 +35,10 @@ function createFunctionalSlots (slots = {}, h) { return children } -export default function createFunctionalComponent (component: Component, mountingOptions: Options) { +export default function createFunctionalComponent ( + component: Component, + mountingOptions: Options +) { if (mountingOptions.context && typeof mountingOptions.context !== 'object') { throwError('mount.context must be an object') } @@ -44,7 +51,12 @@ export default function createFunctionalComponent (component: Component, mountin return h( component, mountingOptions.context || component.FunctionalRenderContext, - (mountingOptions.context && mountingOptions.context.children && mountingOptions.context.children.map(x => typeof x === 'function' ? x(h) : x)) || createFunctionalSlots(mountingOptions.slots, h) + (mountingOptions.context && + mountingOptions.context.children && + mountingOptions.context.children.map( + x => (typeof x === 'function' ? x(h) : x) + )) || + createFunctionalSlots(mountingOptions.slots, h) ) }, name: component.name, diff --git a/packages/create-instance/create-instance.js b/packages/create-instance/create-instance.js index 099befd20..fc8c7b19c 100644 --- a/packages/create-instance/create-instance.js +++ b/packages/create-instance/create-instance.js @@ -23,11 +23,14 @@ export default function createInstance ( if (options.mocks) { addMocks(options.mocks, _Vue) } - if ((component.options && component.options.functional) || component.functional) { + if ( + (component.options && component.options.functional) || + component.functional + ) { component = createFunctionalComponent(component, options) } else if (options.context) { throwError( - 'mount.context can only be used when mounting a functional component' + `mount.context can only be used when mounting a ` + `functional component` ) } @@ -43,8 +46,12 @@ export default function createInstance ( deleteMountingOptions(instanceOptions) - // $FlowIgnore - const stubComponents = createComponentStubs(component.components, options.stubs) + const stubComponents = createComponentStubs( + // $FlowIgnore + component.components, + // $FlowIgnore + options.stubs + ) if (options.stubs) { instanceOptions.components = { ...instanceOptions.components, @@ -53,11 +60,20 @@ export default function createInstance ( } } - Object.keys(component.components || {}).forEach((c) => { - if (component.components[c].extendOptions && - !instanceOptions.components[c]) { + Object.keys(component.components || {}).forEach(c => { + if ( + component.components[c].extendOptions && + !instanceOptions.components[c] + ) { if (options.logModifiedComponents) { - warn(`an extended child component ${c} has been modified to ensure it has the correct instance properties. This means it is not possible to find the component with a component selector. To find the component, you must stub it manually using the stubs mounting option.`) + warn( + `an extended child component ${c} has been modified ` + + `to ensure it has the correct instance properties. ` + + `This means it is not possible to find the component ` + + `with a component selector. To find the component, ` + + `you must stub it manually using the stubs mounting ` + + `option.` + ) } instanceOptions.components[c] = _Vue.extend(component.components[c]) } @@ -67,9 +83,10 @@ export default function createInstance ( _Vue.component(c, stubComponents[c]) }) - const Constructor = vueVersion < 2.3 && typeof component === 'function' - ? component.extend(instanceOptions) - : _Vue.extend(component).extend(instanceOptions) + const Constructor = + vueVersion < 2.3 && typeof component === 'function' + ? component.extend(instanceOptions) + : _Vue.extend(component).extend(instanceOptions) Object.keys(instanceOptions.components || {}).forEach(key => { Constructor.component(key, instanceOptions.components[key]) @@ -82,7 +99,8 @@ export default function createInstance ( // Objects are not resolved in extended components in Vue < 2.5 // https://github.com/vuejs/vue/issues/6436 - if (options.provide && + if ( + options.provide && typeof options.provide === 'object' && vueVersion < 2.5 ) { @@ -96,12 +114,16 @@ export default function createInstance ( const slots = options.slots ? createSlotVNodes(h, options.slots) : undefined - return h(Constructor, { - ref: 'vm', - props: options.propsData, - on: options.listeners, - attrs: options.attrs - }, slots) + return h( + Constructor, + { + ref: 'vm', + props: options.propsData, + on: options.listeners, + attrs: options.attrs + }, + slots + ) } }) diff --git a/packages/create-instance/log-events.js b/packages/create-instance/log-events.js index fffcb783e..26cb07970 100644 --- a/packages/create-instance/log-events.js +++ b/packages/create-instance/log-events.js @@ -1,6 +1,10 @@ // @flow -export function logEvents (vm: Component, emitted: Object, emittedByOrder: Array) { +export function logEvents ( + vm: Component, + emitted: Object, + emittedByOrder: Array +) { const emit = vm.$emit vm.$emit = (name, ...args) => { (emitted[name] || (emitted[name] = [])).push(args) diff --git a/packages/create-instance/validate-slots.js b/packages/create-instance/validate-slots.js index b91d8ac32..1bafc2e5c 100644 --- a/packages/create-instance/validate-slots.js +++ b/packages/create-instance/validate-slots.js @@ -4,29 +4,40 @@ import { throwError } from 'shared/util' import { compileToFunctions } from 'vue-template-compiler' function isValidSlot (slot: any): boolean { - return Array.isArray(slot) || - (slot !== null && typeof slot === 'object') || - typeof slot === 'string' + return ( + Array.isArray(slot) || + (slot !== null && typeof slot === 'object') || + typeof slot === 'string' + ) } function requiresTemplateCompiler (slot) { if (typeof slot === 'string' && !compileToFunctions) { - throwError('vueTemplateCompiler is undefined, you must pass precompiled components if vue-template-compiler is undefined') + throwError( + `vueTemplateCompiler is undefined, you must pass ` + + `precompiled components if vue-template-compiler is ` + + `undefined` + ) } } export function validateSlots (slots: SlotsObject): void { - Object.keys(slots).forEach((key) => { + Object.keys(slots).forEach(key => { if (!isValidSlot(slots[key])) { - throwError('slots[key] must be a Component, string or an array of Components') + throwError( + `slots[key] must be a Component, string or an array ` + `of Components` + ) } requiresTemplateCompiler(slots[key]) if (Array.isArray(slots[key])) { - slots[key].forEach((slotValue) => { + slots[key].forEach(slotValue => { if (!isValidSlot(slotValue)) { - throwError('slots[key] must be a Component, string or an array of Components') + throwError( + `slots[key] must be a Component, string or an array ` + + `of Components` + ) } requiresTemplateCompiler(slotValue) }) diff --git a/packages/server-test-utils/scripts/build.js b/packages/server-test-utils/scripts/build.js index 306de35f4..d10e873a3 100644 --- a/packages/server-test-utils/scripts/build.js +++ b/packages/server-test-utils/scripts/build.js @@ -30,7 +30,9 @@ const rollupOptionsTest = [ } ] -const rollupOptions = process.env.NODE_ENV === 'test' ? rollupOptionsTest : rollupOptionsBuild +const rollupOptions = process.env.NODE_ENV === 'test' + ? rollupOptionsTest + : rollupOptionsBuild rollupOptions.forEach(options => { rollup({ diff --git a/packages/server-test-utils/src/render.js b/packages/server-test-utils/src/render.js index 233f34637..f173aade7 100644 --- a/packages/server-test-utils/src/render.js +++ b/packages/server-test-utils/src/render.js @@ -3,7 +3,10 @@ import renderToString from './renderToString' import cheerio from 'cheerio' -export default function render (component: Component, options: Options = {}): string { +export default function render ( + component: Component, + options: Options = {} +): string { const renderedString = renderToString(component, options) return cheerio.load('')(renderedString) } diff --git a/packages/server-test-utils/src/renderToString.js b/packages/server-test-utils/src/renderToString.js index 62add3479..e4c7c0d4b 100644 --- a/packages/server-test-utils/src/renderToString.js +++ b/packages/server-test-utils/src/renderToString.js @@ -11,17 +11,22 @@ import config from './config' Vue.config.productionTip = false Vue.config.devtools = false -export default function renderToString (component: Component, options: Options = {}): string { +export default function renderToString ( + component: Component, + options: Options = {} +): string { const renderer = createRenderer() if (!renderer) { - throwError('renderToString must be run in node. It cannot be run in a browser') + throwError( + `renderToString must be run in node. It cannot be ` + `run in a browser` + ) } // Remove cached constructor delete component._Ctor if (options.attachToDocument) { - throwError('you cannot use attachToDocument with renderToString') + throwError(`you cannot use attachToDocument with ` + `renderToString`) } const vueClass = options.localVue || testUtils.createLocalVue() const vm = createInstance(component, mergeOptions(options, config), vueClass) diff --git a/packages/shared/compile-template.js b/packages/shared/compile-template.js index e88d40cf9..f0abdce91 100644 --- a/packages/shared/compile-template.js +++ b/packages/shared/compile-template.js @@ -8,7 +8,7 @@ export function compileTemplate (component: Component) { } if (component.components) { - Object.keys(component.components).forEach((c) => { + Object.keys(component.components).forEach(c => { const cmp = component.components[c] if (!cmp.render) { compileTemplate(cmp) diff --git a/packages/shared/merge-options.js b/packages/shared/merge-options.js index 2f5ead619..9bdb58977 100644 --- a/packages/shared/merge-options.js +++ b/packages/shared/merge-options.js @@ -1,14 +1,11 @@ // @flow function getOptions (key, options, config) { - if (options || - (config[key] && Object.keys(config[key]).length > 0)) { + if (options || (config[key] && Object.keys(config[key]).length > 0)) { if (options instanceof Function) { return options } else if (Array.isArray(options)) { - return [ - ...options, - ...Object.keys(config[key] || {})] + return [...options, ...Object.keys(config[key] || {})] } else if (!(config[key] instanceof Function)) { return { ...config[key], @@ -20,10 +17,7 @@ function getOptions (key, options, config) { } } -export function mergeOptions ( - options: Options, - config: Options -): Options { +export function mergeOptions (options: Options, config: Options): Options { return { ...options, logModifiedComponents: config.logModifiedComponents, @@ -31,7 +25,6 @@ export function mergeOptions ( mocks: getOptions('mocks', options.mocks, config), methods: getOptions('methods', options.methods, config), provide: getOptions('provide', options.provide, config), - sync: !!((options.sync || options.sync === undefined)) + sync: !!(options.sync || options.sync === undefined) } } - diff --git a/packages/shared/stub-components.js b/packages/shared/stub-components.js index 9358fcee0..347ff4d8f 100644 --- a/packages/shared/stub-components.js +++ b/packages/shared/stub-components.js @@ -14,14 +14,17 @@ function isVueComponent (comp) { } function isValidStub (stub: any) { - return !!stub && - typeof stub === 'string' || - (stub === true) || - (isVueComponent(stub)) + return ( + (!!stub && typeof stub === 'string') || + stub === true || + isVueComponent(stub) + ) } function isRequiredComponent (name) { - return name === 'KeepAlive' || name === 'Transition' || name === 'TransitionGroup' + return ( + name === 'KeepAlive' || name === 'Transition' || name === 'TransitionGroup' + ) } function getCoreProperties (component: Component): Object { @@ -48,7 +51,11 @@ function createStubFromString ( name: string ): Object { if (!compileToFunctions) { - throwError('vueTemplateCompiler is undefined, you must pass precompiled components if vue-template-compiler is undefined') + throwError( + `vueTemplateCompiler is undefined, you must pass ` + + `precompiled components if vue-template-compiler is ` + + `undefined` + ) } if (templateContainsComponent(templateString, name)) { @@ -92,7 +99,7 @@ export function createComponentStubs ( } if (typeof stub !== 'string') { - throwError('each item in an options.stubs array must be a string') + throwError(`each item in an options.stubs array must be a ` + `string`) } components[stub] = createBlankStub({ name: stub }) }) @@ -102,7 +109,9 @@ export function createComponentStubs ( return } if (!isValidStub(stubs[stub])) { - throwError('options.stub values must be passed a string or component') + throwError( + `options.stub values must be passed a string or ` + `component` + ) } if (stubs[stub] === true) { components[stub] = createBlankStub({ name: stub }) @@ -117,7 +126,11 @@ export function createComponentStubs ( // Remove cached constructor delete originalComponents[stub]._Ctor if (typeof stubs[stub] === 'string') { - components[stub] = createStubFromString(stubs[stub], originalComponents[stub], stub) + components[stub] = createStubFromString( + stubs[stub], + originalComponents[stub], + stub + ) } else { components[stub] = { ...stubs[stub], @@ -127,7 +140,11 @@ export function createComponentStubs ( } else { if (typeof stubs[stub] === 'string') { if (!compileToFunctions) { - throwError('vueTemplateCompiler is undefined, you must pass precompiled components if vue-template-compiler is undefined') + throwError( + `vueTemplateCompiler is undefined, you must pass ` + + `precompiled components if vue-template-compiler is ` + + `undefined` + ) } components[stub] = { ...compileToFunctions(stubs[stub]) @@ -182,14 +199,14 @@ export function createComponentStubsForAll (component: Component): Object { export function createComponentStubsForGlobals (instance: Component): Object { const components = {} - Object.keys(instance.options.components).forEach((c) => { + Object.keys(instance.options.components).forEach(c => { if (isRequiredComponent(c)) { return } components[c] = createBlankStub(instance.options.components[c]) - delete instance.options.components[c]._Ctor // eslint-disable-line no-param-reassign - delete components[c]._Ctor // eslint-disable-line no-param-reassign + delete instance.options.components[c]._Ctor + delete components[c]._Ctor }) return components } diff --git a/packages/shared/util.js b/packages/shared/util.js index ad5a163aa..be9858964 100644 --- a/packages/shared/util.js +++ b/packages/shared/util.js @@ -11,19 +11,26 @@ export function warn (msg: string) { const camelizeRE = /-(\w)/g export const camelize = (str: string) => { - const camelizedStr = str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '') + const camelizedStr = str.replace( + camelizeRE, + (_, c) => (c ? c.toUpperCase() : '') + ) return camelizedStr.charAt(0).toLowerCase() + camelizedStr.slice(1) } /** * Capitalize a string. */ -export const capitalize = (str: string) => str.charAt(0).toUpperCase() + str.slice(1) +export const capitalize = (str: string) => + str.charAt(0).toUpperCase() + str.slice(1) /** * Hyphenate a camelCase string. */ const hyphenateRE = /\B([A-Z])/g -export const hyphenate = (str: string) => str.replace(hyphenateRE, '-$1').toLowerCase() +export const hyphenate = (str: string) => + str.replace(hyphenateRE, '-$1').toLowerCase() -export const vueVersion = Number(`${Vue.version.split('.')[0]}.${Vue.version.split('.')[1]}`) +export const vueVersion = Number( + `${Vue.version.split('.')[0]}.${Vue.version.split('.')[1]}` +) diff --git a/packages/shared/validators.js b/packages/shared/validators.js index bfecebca4..1d0ed05a9 100644 --- a/packages/shared/validators.js +++ b/packages/shared/validators.js @@ -1,10 +1,5 @@ // @flow -import { - throwError, - capitalize, - camelize, - hyphenate -} from './util' +import { throwError, capitalize, camelize, hyphenate } from './util' export function isDomSelector (selector: any) { if (typeof selector !== 'string') { @@ -13,10 +8,16 @@ export function isDomSelector (selector: any) { try { if (typeof document === 'undefined') { - throwError('mount must be run in a browser environment like PhantomJS, jsdom or chrome') + throwError( + `mount must be run in a browser environment like ` + + `PhantomJS, jsdom or chrome` + ) } } catch (error) { - throwError('mount must be run in a browser environment like PhantomJS, jsdom or chrome') + throwError( + `mount must be run in a browser environment like ` + + `PhantomJS, jsdom or chrome` + ) } try { @@ -44,16 +45,19 @@ export function isVueComponent (component: any) { } export function componentNeedsCompiling (component: Component) { - return component && + return ( + component && !component.render && - (component.template || - component.extends || - component.extendOptions) && + (component.template || component.extends || component.extendOptions) && !component.functional + ) } export function isRefSelector (refOptionsObject: any) { - if (typeof refOptionsObject !== 'object' || Object.keys(refOptionsObject || {}).length !== 1) { + if ( + typeof refOptionsObject !== 'object' || + Object.keys(refOptionsObject || {}).length !== 1 + ) { return false } @@ -69,7 +73,7 @@ export function isNameSelector (nameOptionsObject: any) { } export function templateContainsComponent (template: string, name: string) { - return [capitalize, camelize, hyphenate].some((format) => { + return [capitalize, camelize, hyphenate].some(format => { const re = new RegExp(`<${format(name)}\\s*(\\s|>|(\/>))`, 'g') return re.test(template) }) diff --git a/packages/test-utils/scripts/build.js b/packages/test-utils/scripts/build.js index 6198c6232..3566d3d1b 100644 --- a/packages/test-utils/scripts/build.js +++ b/packages/test-utils/scripts/build.js @@ -49,7 +49,9 @@ const rollupOptionsTest = [ } ] -const rollupOptions = process.env.NODE_ENV === 'test' ? rollupOptionsTest : rollupOptionsBuild +const rollupOptions = process.env.NODE_ENV === 'test' + ? rollupOptionsTest + : rollupOptionsBuild rollupOptions.forEach(options => { rollup({ diff --git a/packages/test-utils/src/add-scoped-slots.js b/packages/test-utils/src/add-scoped-slots.js index b19032f28..b99cf93aa 100644 --- a/packages/test-utils/src/add-scoped-slots.js +++ b/packages/test-utils/src/add-scoped-slots.js @@ -8,8 +8,25 @@ function isDestructuringSlotScope (slotScope: string): boolean { function getVueTemplateCompilerHelpers (proxy: Object): Object { const helpers = {} - const names = ['_c', '_o', '_n', '_s', '_l', '_t', '_q', '_i', '_m', '_f', '_k', '_b', '_v', '_e', '_u', '_g'] - names.forEach((name) => { + const names = [ + '_c', + '_o', + '_n', + '_s', + '_l', + '_t', + '_q', + '_i', + '_m', + '_f', + '_k', + '_b', + '_v', + '_e', + '_u', + '_g' + ] + names.forEach(name => { helpers[name] = proxy[name] }) return helpers @@ -17,11 +34,14 @@ function getVueTemplateCompilerHelpers (proxy: Object): Object { export function addScopedSlots (vm: Component, scopedSlots: any) { if (window.navigator.userAgent.match(/PhantomJS/i)) { - throwError('the scopedSlots option does not support PhantomJS. Please use Puppeteer, or pass a component.') + throwError( + `the scopedSlots option does not support PhantomJS. ` + + `Please use Puppeteer, or pass a component.` + ) } if (vueVersion < 2.5) { - throwError('the scopedSlots option is only supported in vue@2.5+.') + throwError(`the scopedSlots option is only supported in ` + `vue@2.5+.`) } vm.$_vueTestUtils_scopedSlots = {} vm.$_vueTestUtils_slotScopes = {} @@ -41,18 +61,29 @@ export function addScopedSlots (vm: Component, scopedSlots: any) { } return scopedSlotFn.call(proxy) } else { - return renderSlot.call(vm._renderProxy, name, feedback, props, bindObject) + return renderSlot.call( + vm._renderProxy, + name, + feedback, + props, + bindObject + ) } } - Object.keys(scopedSlots).forEach((key) => { + Object.keys(scopedSlots).forEach(key => { const template = scopedSlots[key].trim() if (template.substr(0, 9) === ' 1) { warn( - ' can only be used on a single element. Use ' + + ` can only be used on a single element. ` + `Use ` + ' for lists.' ) } @@ -112,13 +112,16 @@ export default { const data: Object = (child.data || (child.data = {})) const oldRawChild: ?VNode = this._vnode const oldChild: ?VNode = getRealChild(oldRawChild) - if (child.data.directives && child.data.directives.some(d => d.name === 'show')) { + if (child.data.directives && + child.data.directives.some(d => d.name === 'show')) { child.data.show = true } // mark v-show - // so that the transition module can hand over the control to the directive - if (child.data.directives && child.data.directives.some(d => d.name === 'show')) { + // so that the transition module can hand over the control + // to the directive + if (child.data.directives && + child.data.directives.some(d => d.name === 'show')) { child.data.show = true } if ( @@ -127,7 +130,8 @@ export default { !isSameChild(child, oldChild) && !isAsyncPlaceholder(oldChild) && // #6687 component root is a comment node - !(oldChild.componentInstance && oldChild.componentInstance._vnode.isComment) + !(oldChild.componentInstance && + oldChild.componentInstance._vnode.isComment) ) { oldChild.data = { ...data } } diff --git a/packages/test-utils/src/consts.js b/packages/test-utils/src/consts.js index f72395951..276c020f8 100644 --- a/packages/test-utils/src/consts.js +++ b/packages/test-utils/src/consts.js @@ -4,5 +4,8 @@ export const NAME_SELECTOR = 'NAME_SELECTOR' export const COMPONENT_SELECTOR = 'COMPONENT_SELECTOR' export const REF_SELECTOR = 'REF_SELECTOR' export const DOM_SELECTOR = 'DOM_SELECTOR' -export const VUE_VERSION = Number(`${Vue.version.split('.')[0]}.${Vue.version.split('.')[1]}`) -export const FUNCTIONAL_OPTIONS = VUE_VERSION >= 2.5 ? 'fnOptions' : 'functionalOptions' +export const VUE_VERSION = Number( + `${Vue.version.split('.')[0]}.${Vue.version.split('.')[1]}` +) +export const FUNCTIONAL_OPTIONS = + VUE_VERSION >= 2.5 ? 'fnOptions' : 'functionalOptions' diff --git a/packages/test-utils/src/create-local-vue.js b/packages/test-utils/src/create-local-vue.js index 5f3cd4d60..80b655a90 100644 --- a/packages/test-utils/src/create-local-vue.js +++ b/packages/test-utils/src/create-local-vue.js @@ -11,9 +11,8 @@ function createLocalVue (): Component { Object.keys(Vue).forEach(key => { if (!instance.hasOwnProperty(key)) { const original = Vue[key] - instance[key] = typeof original === 'object' - ? cloneDeep(original) - : original + instance[key] = + typeof original === 'object' ? cloneDeep(original) : original } }) diff --git a/packages/test-utils/src/error-handler.js b/packages/test-utils/src/error-handler.js index c87d1916e..142a3ce77 100644 --- a/packages/test-utils/src/error-handler.js +++ b/packages/test-utils/src/error-handler.js @@ -1,7 +1,8 @@ export default function errorHandler (errorOrString, vm) { - const error = (typeof errorOrString === 'object') - ? errorOrString - : new Error(errorOrString) + const error = + typeof errorOrString === 'object' + ? errorOrString + : new Error(errorOrString) vm._error = error diff --git a/packages/test-utils/src/error-wrapper.js b/packages/test-utils/src/error-wrapper.js index 51603ae04..63d409656 100644 --- a/packages/test-utils/src/error-wrapper.js +++ b/packages/test-utils/src/error-wrapper.js @@ -10,27 +10,49 @@ export default class ErrorWrapper implements BaseWrapper { } at (): void { - throwError(`find did not return ${this.selector}, cannot call at() on empty Wrapper`) + throwError( + `find did not return ${this.selector}, cannot call at() on empty Wrapper` + ) } attributes (): void { - throwError(`find did not return ${this.selector}, cannot call attributes() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call attributes() on empty Wrapper` + ) } classes (): void { - throwError(`find did not return ${this.selector}, cannot call classes() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call classes() on empty Wrapper` + ) } contains (): void { - throwError(`find did not return ${this.selector}, cannot call contains() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call contains() on empty Wrapper` + ) } emitted (): void { - throwError(`find did not return ${this.selector}, cannot call emitted() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call emitted() on empty Wrapper` + ) } emittedByOrder (): void { - throwError(`find did not return ${this.selector}, cannot call emittedByOrder() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call emittedByOrder() on empty Wrapper` + ) } exists (): boolean { @@ -38,106 +60,207 @@ export default class ErrorWrapper implements BaseWrapper { } filter (): void { - throwError(`find did not return ${this.selector}, cannot call filter() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call filter() on empty Wrapper` + ) } visible (): void { - throwError(`find did not return ${this.selector}, cannot call visible() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call visible() on empty Wrapper` + ) } hasAttribute (): void { - throwError(`find did not return ${this.selector}, cannot call hasAttribute() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call hasAttribute() on empty Wrapper` + ) } hasClass (): void { - throwError(`find did not return ${this.selector}, cannot call hasClass() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call hasClass() on empty Wrapper` + ) } hasProp (): void { - throwError(`find did not return ${this.selector}, cannot call hasProp() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call hasProp() on empty Wrapper` + ) } hasStyle (): void { - throwError(`find did not return ${this.selector}, cannot call hasStyle() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call hasStyle() on empty Wrapper` + ) } findAll (): void { - throwError(`find did not return ${this.selector}, cannot call findAll() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call findAll() on empty Wrapper` + ) } find (): void { - throwError(`find did not return ${this.selector}, cannot call find() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call find() on empty Wrapper` + ) } html (): void { - throwError(`find did not return ${this.selector}, cannot call html() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call html() on empty Wrapper` + ) } is (): void { - throwError(`find did not return ${this.selector}, cannot call is() on empty Wrapper`) + throwError( + `find did not return ${this.selector}, cannot call is() on empty Wrapper` + ) } isEmpty (): void { - throwError(`find did not return ${this.selector}, cannot call isEmpty() on empty Wrapper`) + 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`) + 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`) + throwError( + `find did not return ${ + this.selector + }, cannot call isVueInstance() on empty Wrapper` + ) } name (): void { - throwError(`find did not return ${this.selector}, cannot call name() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call name() on empty Wrapper` + ) } props (): void { - throwError(`find did not return ${this.selector}, cannot call props() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call props() on empty Wrapper` + ) } text (): void { - throwError(`find did not return ${this.selector}, cannot call text() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call text() on empty Wrapper` + ) } setComputed (): void { - throwError(`find did not return ${this.selector}, cannot call setComputed() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call setComputed() on empty Wrapper` + ) } setData (): void { - throwError(`find did not return ${this.selector}, cannot call setData() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call setData() on empty Wrapper` + ) } setMethods (): void { - throwError(`find did not return ${this.selector}, cannot call setMethods() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call setMethods() on empty Wrapper` + ) } setProps (): void { - throwError(`find did not return ${this.selector}, cannot call setProps() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call setProps() on empty Wrapper` + ) } setValue (): void { - throwError(`find did not return ${this.selector}, cannot call setValue() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call setValue() on empty Wrapper` + ) } setChecked (): void { - throwError(`find did not return ${this.selector}, cannot call setChecked() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call setChecked() on empty Wrapper` + ) } setSelected (): void { - throwError(`find did not return ${this.selector}, cannot call setSelected() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call setSelected() on empty Wrapper` + ) } trigger (): void { - throwError(`find did not return ${this.selector}, cannot call trigger() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call trigger() on empty Wrapper` + ) } update (): void { - throwError(`update has been removed from vue-test-utils. All updates are now synchronous by default`) + throwError( + `update has been removed from vue-test-utils.` + + `All updates are now synchronous by default` + ) } destroy (): void { - throwError(`find did not return ${this.selector}, cannot call destroy() on empty Wrapper`) + throwError( + `find did not return ${ + this.selector + }, cannot call destroy() on empty Wrapper` + ) } } diff --git a/packages/test-utils/src/find-vnodes.js b/packages/test-utils/src/find-vnodes.js index 6ee2a1e4d..8579fdd61 100644 --- a/packages/test-utils/src/find-vnodes.js +++ b/packages/test-utils/src/find-vnodes.js @@ -1,17 +1,13 @@ // @flow -import { - REF_SELECTOR -} from './consts' -import { - throwError -} from 'shared/util' +import { REF_SELECTOR } from './consts' +import { throwError } from 'shared/util' function findAllVNodes (vnode: VNode, nodes: Array = []): Array { nodes.push(vnode) if (Array.isArray(vnode.children)) { - vnode.children.forEach((childVNode) => { + vnode.children.forEach(childVNode => { findAllVNodes(childVNode, nodes) }) } @@ -25,7 +21,9 @@ function findAllVNodes (vnode: VNode, nodes: Array = []): Array { function removeDuplicateNodes (vNodes: Array): Array { const vNodeElms = vNodes.map(vNode => vNode.elm) - return vNodes.filter((vNode, index) => index === vNodeElms.indexOf(vNode.elm)) + return vNodes.filter( + (vNode, index) => index === vNodeElms.indexOf(vNode.elm) + ) } function nodeMatchesRef (node: VNode, refName: string): boolean { @@ -37,9 +35,9 @@ function findVNodesByRef (vNode: VNode, refName: string): Array { const refFilteredNodes = nodes.filter(node => nodeMatchesRef(node, refName)) // Only return refs defined on top-level VNode to provide the same // behavior as selecting via vm.$ref.{someRefName} - const mainVNodeFilteredNodes = refFilteredNodes.filter(node => ( - !!vNode.context.$refs[node.data.ref] - )) + const mainVNodeFilteredNodes = refFilteredNodes.filter( + node => !!vNode.context.$refs[node.data.ref] + ) return removeDuplicateNodes(mainVNodeFilteredNodes) } @@ -47,14 +45,11 @@ function nodeMatchesSelector (node: VNode, selector: string): boolean { return node.elm && node.elm.getAttribute && node.elm.matches(selector) } -function findVNodesBySelector ( - vNode: VNode, - selector: string -): Array { +function findVNodesBySelector (vNode: VNode, selector: string): Array { const nodes = findAllVNodes(vNode) - const filteredNodes = nodes.filter(node => ( + const filteredNodes = nodes.filter(node => nodeMatchesSelector(node, selector) - )) + ) return removeDuplicateNodes(filteredNodes) } @@ -66,7 +61,9 @@ export default function findVnodes ( ): Array { if (selectorType === REF_SELECTOR) { if (!vm) { - throwError('$ref selectors can only be used on Vue component wrappers') + throwError( + `$ref selectors can only be used on Vue component ` + `wrappers` + ) } // $FlowIgnore return findVNodesByRef(vnode, selector.ref) diff --git a/packages/test-utils/src/find-vue-components.js b/packages/test-utils/src/find-vue-components.js index 28e73e298..54c936d9a 100644 --- a/packages/test-utils/src/find-vue-components.js +++ b/packages/test-utils/src/find-vue-components.js @@ -1,18 +1,13 @@ // @flow -import { - FUNCTIONAL_OPTIONS, - VUE_VERSION -} from './consts' -import { - throwError -} from 'shared/util' +import { FUNCTIONAL_OPTIONS, VUE_VERSION } from './consts' +import { throwError } from 'shared/util' export function findAllVueComponentsFromVm ( vm: Component, components: Array = [] ): Array { components.push(vm) - vm.$children.forEach((child) => { + vm.$children.forEach(child => { findAllVueComponentsFromVm(child, components) }) @@ -27,7 +22,7 @@ function findAllVueComponentsFromVnode ( components.push(vnode.child) } if (vnode.children) { - vnode.children.forEach((child) => { + vnode.children.forEach(child => { findAllVueComponentsFromVnode(child, components) }) } @@ -43,7 +38,7 @@ function findAllFunctionalComponentsFromVnode ( components.push(vnode) } if (vnode.children) { - vnode.children.forEach((child) => { + vnode.children.forEach(child => { findAllFunctionalComponentsFromVnode(child, components) }) } @@ -51,13 +46,16 @@ function findAllFunctionalComponentsFromVnode ( } export function vmCtorMatchesName (vm: Component, name: string): boolean { - return !!((vm.$vnode && vm.$vnode.componentOptions && - vm.$vnode.componentOptions.Ctor.options.name === name) || + return !!( + (vm.$vnode && + vm.$vnode.componentOptions && + vm.$vnode.componentOptions.Ctor.options.name === name) || (vm._vnode && - vm._vnode.functionalOptions && - vm._vnode.functionalOptions.name === name) || - vm.$options && vm.$options.name === name || - vm.options && vm.options.name === name) + vm._vnode.functionalOptions && + vm._vnode.functionalOptions.name === name) || + (vm.$options && vm.$options.name === name) || + (vm.options && vm.options.name === name) + ) } export function vmCtorMatchesSelector (component: Component, selector: Object) { @@ -67,14 +65,18 @@ export function vmCtorMatchesSelector (component: Component, selector: Object) { } const constructor = component.__proto__.constructor return Object.keys(Ctor || {}).some(c => { - return Ctor[c] === constructor || - Ctor[c] === constructor.super + return Ctor[c] === constructor || Ctor[c] === constructor.super }) } -export function vmFunctionalCtorMatchesSelector (component: VNode, Ctor: Object) { +export function vmFunctionalCtorMatchesSelector ( + component: VNode, + Ctor: Object +) { if (VUE_VERSION < 2.3) { - throwError('find for functional components is not support in Vue < 2.3') + throwError( + `find for functional components is not support in ` + `Vue < 2.3` + ) } if (!Ctor) { @@ -97,19 +99,24 @@ export default function findVueComponents ( const nodes = root._vnode ? findAllFunctionalComponentsFromVnode(root._vnode) : findAllFunctionalComponentsFromVnode(root) - return nodes.filter(node => - vmFunctionalCtorMatchesSelector(node, selector._Ctor) || - node[FUNCTIONAL_OPTIONS].name === selector.name + return nodes.filter( + node => + vmFunctionalCtorMatchesSelector(node, selector._Ctor) || + node[FUNCTIONAL_OPTIONS].name === selector.name ) } - const nameSelector = typeof selector === 'function' ? selector.options.name : selector.name + const nameSelector = + typeof selector === 'function' ? selector.options.name : selector.name const components = root._isVue ? findAllVueComponentsFromVm(root) : findAllVueComponentsFromVnode(root) - return components.filter((component) => { + return components.filter(component => { if (!component.$vnode && !component.$options.extends) { return false } - return vmCtorMatchesSelector(component, selector) || vmCtorMatchesName(component, nameSelector) + return ( + vmCtorMatchesSelector(component, selector) || + vmCtorMatchesName(component, nameSelector) + ) }) } diff --git a/packages/test-utils/src/find.js b/packages/test-utils/src/find.js index 7b178b649..ef983d7f1 100644 --- a/packages/test-utils/src/find.js +++ b/packages/test-utils/src/find.js @@ -3,11 +3,7 @@ import findVnodes from './find-vnodes' import findVueComponents from './find-vue-components' import findDOMNodes from './find-dom-nodes' -import { - COMPONENT_SELECTOR, - NAME_SELECTOR, - DOM_SELECTOR -} from './consts' +import { COMPONENT_SELECTOR, NAME_SELECTOR, DOM_SELECTOR } from './consts' import Vue from 'vue' import getSelectorTypeOrThrow from './get-selector-type' import { throwError } from 'shared/util' @@ -21,7 +17,11 @@ export default function find ( const selectorType = getSelectorTypeOrThrow(selector, 'find') if (!vnode && !vm && selectorType !== DOM_SELECTOR) { - throwError('cannot find a Vue instance on a DOM node. The node you are calling find on does not exist in the VDom. Are you adding the node as innerHTML?') + throwError( + `cannot find a Vue instance on a DOM node. The node ` + + `you are calling find on does not exist in the ` + + `VDom. Are you adding the node as innerHTML?` + ) } if (selectorType === COMPONENT_SELECTOR || selectorType === NAME_SELECTOR) { @@ -32,7 +32,12 @@ export default function find ( return findVueComponents(root, selectorType, selector) } - if (vm && vm.$refs && selector.ref in vm.$refs && vm.$refs[selector.ref] instanceof Vue) { + if ( + vm && + vm.$refs && + selector.ref in vm.$refs && + vm.$refs[selector.ref] instanceof Vue + ) { return [vm.$refs[selector.ref]] } diff --git a/packages/test-utils/src/get-selector-type.js b/packages/test-utils/src/get-selector-type.js index 898c403ff..a4b25473c 100644 --- a/packages/test-utils/src/get-selector-type.js +++ b/packages/test-utils/src/get-selector-type.js @@ -6,9 +6,7 @@ import { isRefSelector, isVueComponent } from 'shared/validators' -import { - throwError -} from 'shared/util' +import { throwError } from 'shared/util' import { REF_SELECTOR, COMPONENT_SELECTOR, @@ -16,11 +14,17 @@ import { DOM_SELECTOR } from './consts' -export default function getSelectorTypeOrThrow (selector: Selector, methodName: string): string | void { +export default function getSelectorTypeOrThrow ( + selector: Selector, + methodName: string +): string | void { if (isDomSelector(selector)) return DOM_SELECTOR if (isNameSelector(selector)) return NAME_SELECTOR if (isVueComponent(selector)) return COMPONENT_SELECTOR if (isRefSelector(selector)) return REF_SELECTOR - throwError(`wrapper.${methodName}() must be passed a valid CSS selector, Vue constructor, or valid find option object`) + throwError( + `wrapper.${methodName}() must be passed a valid CSS selector, ` + + `Vue constructor, or valid find option object` + ) } diff --git a/packages/test-utils/src/index.js b/packages/test-utils/src/index.js index 2c1982aa9..83bb7d80d 100644 --- a/packages/test-utils/src/index.js +++ b/packages/test-utils/src/index.js @@ -8,7 +8,10 @@ import config from './config' import { warn } from 'shared/util' function shallow (component, options) { - warn('shallow has been renamed to shallowMount. shallow will be removed in 1.0.0, use shallowMount instead') + warn( + `shallow has been renamed to shallowMount. shallow ` + + `will be removed in 1.0.0, use shallowMount instead` + ) return shallowMount(component, options) } diff --git a/packages/test-utils/src/matches-polyfill.js b/packages/test-utils/src/matches-polyfill.js index f572df7d5..cecb679a6 100644 --- a/packages/test-utils/src/matches-polyfill.js +++ b/packages/test-utils/src/matches-polyfill.js @@ -1,14 +1,14 @@ if (typeof Element !== 'undefined' && !Element.prototype.matches) { Element.prototype.matches = - Element.prototype.matchesSelector || - Element.prototype.mozMatchesSelector || - Element.prototype.msMatchesSelector || - Element.prototype.oMatchesSelector || - Element.prototype.webkitMatchesSelector || - function (s) { - const matches = (this.document || this.ownerDocument).querySelectorAll(s) - let i = matches.length - while (--i >= 0 && matches.item(i) !== this) {} - return i > -1 - } + Element.prototype.matchesSelector || + Element.prototype.mozMatchesSelector || + Element.prototype.msMatchesSelector || + Element.prototype.oMatchesSelector || + Element.prototype.webkitMatchesSelector || + function (s) { + const matches = (this.document || this.ownerDocument).querySelectorAll(s) + let i = matches.length + while (--i >= 0 && matches.item(i) !== this) {} + return i > -1 + } } diff --git a/packages/test-utils/src/mount.js b/packages/test-utils/src/mount.js index 6d265532c..5372c0f0f 100644 --- a/packages/test-utils/src/mount.js +++ b/packages/test-utils/src/mount.js @@ -17,7 +17,10 @@ import { addScopedSlots } from './add-scoped-slots' Vue.config.productionTip = false Vue.config.devtools = false -export default function mount (component: Component, options: Options = {}): VueWrapper { +export default function mount ( + component: Component, + options: Options = {} +): VueWrapper { const existingErrorHandler = Vue.config.errorHandler Vue.config.errorHandler = errorHandler @@ -28,9 +31,7 @@ export default function mount (component: Component, options: Options = {}): Vue const vueConstructor = options.localVue || createLocalVue() - const elm = options.attachToDocument - ? createElement() - : undefined + const elm = options.attachToDocument ? createElement() : undefined const mergedOptions = mergeOptions(options, config) @@ -56,10 +57,12 @@ export default function mount (component: Component, options: Options = {}): Vue vm.$forceUpdate() } - const componentsWithError = findAllVueComponentsFromVm(vm).filter(c => c._error) + const componentsWithError = findAllVueComponentsFromVm(vm).filter( + c => c._error + ) if (componentsWithError.length > 0) { - throw (componentsWithError[0]._error) + throw componentsWithError[0]._error } Vue.config.errorHandler = existingErrorHandler diff --git a/packages/test-utils/src/order-watchers.js b/packages/test-utils/src/order-watchers.js index 3563aedc8..ddc690f3b 100644 --- a/packages/test-utils/src/order-watchers.js +++ b/packages/test-utils/src/order-watchers.js @@ -17,7 +17,7 @@ function orderVmWatchers (vm) { } if (vm._computedWatchers) { - Object.keys(vm._computedWatchers).forEach((computedWatcher) => { + Object.keys(vm._computedWatchers).forEach(computedWatcher => { orderDeps(vm._computedWatchers[computedWatcher]) }) } diff --git a/packages/test-utils/src/set-watchers-to-sync.js b/packages/test-utils/src/set-watchers-to-sync.js index e6cdf0161..d5a06f44a 100644 --- a/packages/test-utils/src/set-watchers-to-sync.js +++ b/packages/test-utils/src/set-watchers-to-sync.js @@ -18,7 +18,7 @@ export function setWatchersToSync (vm) { } if (vm._computedWatchers) { - Object.keys(vm._computedWatchers).forEach((computedWatcher) => { + Object.keys(vm._computedWatchers).forEach(computedWatcher => { setWatcherSync(vm._computedWatchers[computedWatcher]) }) } @@ -32,7 +32,7 @@ export function setWatchersToSync (vm) { vm._update = function (vnode, hydrating) { this.$_vueTestUtils_updateInSetWatcherSync(vnode, hydrating) if (VUE_VERSION >= 2.1 && this._isMounted && this.$options.updated) { - this.$options.updated.forEach((handler) => { + this.$options.updated.forEach(handler => { handler.call(this) }) } diff --git a/packages/test-utils/src/shallow-mount.js b/packages/test-utils/src/shallow-mount.js index 037fd0720..d07869074 100644 --- a/packages/test-utils/src/shallow-mount.js +++ b/packages/test-utils/src/shallow-mount.js @@ -8,10 +8,7 @@ import { createComponentStubsForAll, createComponentStubsForGlobals } from 'shared/stub-components' -import { camelize, - capitalize, - hyphenate -} from 'shared/util' +import { camelize, capitalize, hyphenate } from 'shared/util' export default function shallowMount ( component: Component, diff --git a/packages/test-utils/src/vue-wrapper.js b/packages/test-utils/src/vue-wrapper.js index 1428b0879..3f1820f76 100644 --- a/packages/test-utils/src/vue-wrapper.js +++ b/packages/test-utils/src/vue-wrapper.js @@ -8,16 +8,16 @@ export default class VueWrapper extends Wrapper implements BaseWrapper { constructor (vm: Component, options: WrapperOptions) { super(vm._vnode, options) - // $FlowIgnore : issue with defineProperty - https://github.com/facebook/flow/issues/285 - Object.defineProperty(this, 'vnode', ({ + // $FlowIgnore : issue with defineProperty + Object.defineProperty(this, 'vnode', { get: () => vm._vnode, set: () => {} - })) + }) // $FlowIgnore - Object.defineProperty(this, 'element', ({ + Object.defineProperty(this, 'element', { get: () => vm.$el, set: () => {} - })) + }) this.vm = vm if (options.sync) { setWatchersToSync(vm) diff --git a/packages/test-utils/src/warn-if-no-window.js b/packages/test-utils/src/warn-if-no-window.js index a640d5077..1913fd9d8 100644 --- a/packages/test-utils/src/warn-if-no-window.js +++ b/packages/test-utils/src/warn-if-no-window.js @@ -3,9 +3,15 @@ import { throwError } from 'shared/util' export default function warnIfNoWindow () { if (typeof window === 'undefined') { throwError( - 'window is undefined, vue-test-utils needs to be run in a browser environment.\n' + - 'You can run the tests in node using jsdom + jsdom-global.\n' + - 'See https://vue-test-utils.vuejs.org/guides/common-tips.html for more details.' + `window is undefined, vue-test-utils needs to be ` + + `run in a browser environment. +` + + (`You can run the tests in node using jsdom + ` + + `jsdom-global. +`) + + (`See ` + + `https://vue-test-utils.vuejs.org/guides/common-tips.html ` + + `for more details.`) ) } } diff --git a/packages/test-utils/src/wrapper-array.js b/packages/test-utils/src/wrapper-array.js index 76b011d3b..4bf9d2ccf 100644 --- a/packages/test-utils/src/wrapper-array.js +++ b/packages/test-utils/src/wrapper-array.js @@ -2,10 +2,7 @@ import type Wrapper from './wrapper' import type VueWrapper from './vue-wrapper' -import { - throwError, - warn -} from 'shared/util' +import { throwError, warn } from 'shared/util' export default class WrapperArray implements BaseWrapper { wrappers: Array; @@ -26,13 +23,19 @@ export default class WrapperArray implements BaseWrapper { attributes (): void { this.throwErrorIfWrappersIsEmpty('attributes') - throwError('attributes must be called on a single wrapper, use at(i) to access a wrapper') + throwError( + `attributes must be called on a single wrapper, use ` + + `at(i) to access a wrapper` + ) } classes (): void { this.throwErrorIfWrappersIsEmpty('classes') - throwError('classes must be called on a single wrapper, use at(i) to access a wrapper') + throwError( + `classes must be called on a single wrapper, use ` + + `at(i) to access a wrapper` + ) } contains (selector: Selector): boolean { @@ -58,19 +61,27 @@ export default class WrapperArray implements BaseWrapper { emitted (): void { this.throwErrorIfWrappersIsEmpty('emitted') - throwError('emitted must be called on a single wrapper, use at(i) to access a wrapper') + throwError( + `emitted must be called on a single wrapper, use ` + + `at(i) to access a wrapper` + ) } emittedByOrder (): void { this.throwErrorIfWrappersIsEmpty('emittedByOrder') - throwError('emittedByOrder must be called on a single wrapper, use at(i) to access a wrapper') + throwError( + `emittedByOrder must be called on a single wrapper, ` + + `use at(i) to access a wrapper` + ) } hasAttribute (attribute: string, value: string): boolean { this.throwErrorIfWrappersIsEmpty('hasAttribute') - return this.wrappers.every(wrapper => wrapper.hasAttribute(attribute, value)) + return this.wrappers.every(wrapper => + wrapper.hasAttribute(attribute, value) + ) } hasClass (className: string): boolean { @@ -94,19 +105,28 @@ export default class WrapperArray implements BaseWrapper { findAll (): void { this.throwErrorIfWrappersIsEmpty('findAll') - throwError('findAll must be called on a single wrapper, use at(i) to access a wrapper') + throwError( + `findAll must be called on a single wrapper, use ` + + `at(i) to access a wrapper` + ) } find (): void { this.throwErrorIfWrappersIsEmpty('find') - throwError('find must be called on a single wrapper, use at(i) to access a wrapper') + throwError( + `find must be called on a single wrapper, use at(i) ` + + `to access a wrapper` + ) } html (): void { this.throwErrorIfWrappersIsEmpty('html') - throwError('html must be called on a single wrapper, use at(i) to access a wrapper') + throwError( + `html must be called on a single wrapper, use at(i) ` + + `to access a wrapper` + ) } is (selector: Selector): boolean { @@ -136,19 +156,28 @@ export default class WrapperArray implements BaseWrapper { name (): void { this.throwErrorIfWrappersIsEmpty('name') - throwError('name must be called on a single wrapper, use at(i) to access a wrapper') + throwError( + `name must be called on a single wrapper, use at(i) ` + + `to access a wrapper` + ) } props (): void { this.throwErrorIfWrappersIsEmpty('props') - throwError('props must be called on a single wrapper, use at(i) to access a wrapper') + throwError( + `props must be called on a single wrapper, use ` + + `at(i) to access a wrapper` + ) } text (): void { this.throwErrorIfWrappersIsEmpty('text') - throwError('text must be called on a single wrapper, use at(i) to access a wrapper') + throwError( + `text must be called on a single wrapper, use at(i) ` + + `to access a wrapper` + ) } throwErrorIfWrappersIsEmpty (method: string): void { @@ -196,7 +225,10 @@ export default class WrapperArray implements BaseWrapper { setSelected (): void { this.throwErrorIfWrappersIsEmpty('setSelected') - throwError('setSelected must be called on a single wrapper, use at(i) to access a wrapper') + throwError( + `setSelected must be called on a single wrapper, ` + + `use at(i) to access a wrapper` + ) } trigger (event: string, options: Object): void { @@ -207,7 +239,10 @@ export default class WrapperArray implements BaseWrapper { update (): void { this.throwErrorIfWrappersIsEmpty('update') - warn('update has been removed. All changes are now synchrnous without calling update') + warn( + `update has been removed. All changes are now ` + + `synchrnous without calling update` + ) } destroy (): void { diff --git a/packages/test-utils/src/wrapper.js b/packages/test-utils/src/wrapper.js index 5f0431a16..81a9b2161 100644 --- a/packages/test-utils/src/wrapper.js +++ b/packages/test-utils/src/wrapper.js @@ -17,21 +17,16 @@ import { } from './find-vue-components' import WrapperArray from './wrapper-array' import ErrorWrapper from './error-wrapper' -import { - throwError, - warn -} from 'shared/util' +import { throwError, warn } from 'shared/util' import findAll from './find' import createWrapper from './create-wrapper' -import { - orderWatchers -} from './order-watchers' +import { orderWatchers } from './order-watchers' export default class Wrapper implements BaseWrapper { vnode: VNode | null; vm: Component | null; _emitted: { [name: string]: Array> }; - _emittedByOrder: Array<{ name: string; args: Array }>; + _emittedByOrder: Array<{ name: string, args: Array }>; isVm: boolean; element: Element; update: Function; @@ -47,11 +42,16 @@ export default class Wrapper implements BaseWrapper { this.vnode = node this.element = node.elm } - if (this.vnode && (this.vnode[FUNCTIONAL_OPTIONS] || this.vnode.functionalContext)) { + if ( + this.vnode && + (this.vnode[FUNCTIONAL_OPTIONS] || this.vnode.functionalContext) + ) { this.isFunctionalComponent = true } this.options = options - this.version = Number(`${Vue.version.split('.')[0]}.${Vue.version.split('.')[1]}`) + this.version = Number( + `${Vue.version.split('.')[0]}.${Vue.version.split('.')[1]}` + ) } at () { @@ -75,22 +75,24 @@ export default class Wrapper implements BaseWrapper { * Returns an Array containing all the classes on the element */ classes (): Array { - // works for HTML Element and SVG Element const className = this.element.getAttribute('class') let classes = className ? className.split(' ') : [] // Handle converting cssmodules identifiers back to the original class name if (this.vm && this.vm.$style) { const cssModuleIdentifiers = {} let moduleIdent - Object.keys(this.vm.$style).forEach((key) => { - // $FlowIgnore : Flow thinks vm is a property - moduleIdent = this.vm.$style[key] + Object.keys(this.vm.$style).forEach(key => { + moduleIdent = this.vm && this.vm.$style[key] // CSS Modules may be multi-class if they extend others. // Extended classes should be already present in $style. - moduleIdent = moduleIdent.split(' ')[0] - cssModuleIdentifiers[moduleIdent] = key + if (moduleIdent) { + moduleIdent = moduleIdent.split(' ')[0] + cssModuleIdentifiers[moduleIdent] = key + } }) - classes = classes.map(className => cssModuleIdentifiers[className] || className) + classes = classes.map( + className => cssModuleIdentifiers[className] || className + ) } return classes } @@ -110,7 +112,7 @@ export default class Wrapper implements BaseWrapper { */ emitted (event?: string) { if (!this._emitted && !this.vm) { - throwError('wrapper.emitted() can only be called on a Vue instance') + throwError(`wrapper.emitted() can only be called on a Vue ` + `instance`) } if (event) { return this._emitted[event] @@ -123,7 +125,9 @@ export default class Wrapper implements BaseWrapper { */ emittedByOrder () { if (!this._emittedByOrder && !this.vm) { - throwError('wrapper.emittedByOrder() can only be called on a Vue instance') + throwError( + `wrapper.emittedByOrder() can only be called on a ` + `Vue instance` + ) } return this._emittedByOrder } @@ -143,10 +147,14 @@ export default class Wrapper implements BaseWrapper { } /** - * Utility to check wrapper is visible. Returns false if a parent element has display: none or visibility: hidden style. + * 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') + warn( + `visible has been deprecated and will be removed in ` + + `version 1, use isVisible instead` + ) let element = this.element @@ -155,7 +163,11 @@ export default class Wrapper implements BaseWrapper { } while (element) { - if (element.style && (element.style.visibility === 'hidden' || element.style.display === 'none')) { + if ( + element.style && + (element.style.visibility === 'hidden' || + element.style.display === 'none') + ) { return false } element = element.parentElement @@ -168,14 +180,22 @@ export default class Wrapper implements BaseWrapper { * Checks if wrapper has an attribute with matching value */ hasAttribute (attribute: string, value: string) { - warn('hasAttribute() has been deprecated and will be removed in version 1.0.0. Use attributes() instead—https://vue-test-utils.vuejs.org/en/api/wrapper/attributes') + warn( + `hasAttribute() has been deprecated and will be ` + + `removed in version 1.0.0. Use attributes() ` + + `instead—https://vue-test-utils.vuejs.org/en/api/wrapper/attributes` + ) if (typeof attribute !== 'string') { - throwError('wrapper.hasAttribute() must be passed attribute as a 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') + throwError( + `wrapper.hasAttribute() must be passed value as a ` + `string` + ) } return !!(this.element && this.element.getAttribute(attribute) === value) @@ -185,7 +205,11 @@ export default class Wrapper implements BaseWrapper { * Asserts wrapper has a class name */ hasClass (className: string) { - warn('hasClass() has been deprecated and will be removed in version 1.0.0. Use classes() instead—https://vue-test-utils.vuejs.org/en/api/wrapper/classes') + warn( + `hasClass() has been deprecated and will be removed ` + + `in version 1.0.0. Use classes() ` + + `instead—https://vue-test-utils.vuejs.org/en/api/wrapper/classes` + ) let targetClass = className if (typeof targetClass !== 'string') { @@ -208,7 +232,11 @@ export default class Wrapper implements BaseWrapper { * Asserts wrapper has a prop name */ hasProp (prop: string, value: string) { - warn('hasProp() has been deprecated and will be removed in version 1.0.0. Use props() instead—https://vue-test-utils.vuejs.org/en/api/wrapper/props') + warn( + `hasProp() has been deprecated and will be removed ` + + `in version 1.0.0. Use props() ` + + `instead—https://vue-test-utils.vuejs.org/en/api/wrapper/props` + ) if (!this.isVueInstance()) { throwError('wrapper.hasProp() must be called on a Vue instance') @@ -217,8 +245,14 @@ export default class Wrapper implements BaseWrapper { 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) { + // $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 } @@ -229,10 +263,14 @@ export default class Wrapper implements BaseWrapper { * Checks if wrapper has a style with value */ hasStyle (style: string, value: string) { - warn('hasStyle() has been deprecated and will be removed in version 1.0.0. Use wrapper.element.style instead') + 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') + throwError(`wrapper.hasStyle() must be passed style as a ` + `string`) } if (typeof value !== 'string') { @@ -240,8 +278,15 @@ export default class Wrapper implements BaseWrapper { } /* istanbul ignore next */ - if (navigator.userAgent.includes && (navigator.userAgent.includes('node.js') || navigator.userAgent.includes('jsdom'))) { - console.warn('wrapper.hasStyle is not fully supported when running jsdom - only inline styles are supported') // eslint-disable-line no-console + 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') @@ -265,7 +310,8 @@ export default class Wrapper implements BaseWrapper { } /** - * Finds first node in tree of the current wrapper that matches the provided selector. + * Finds first node in tree of the current wrapper that + * matches the provided selector. */ find (selector: Selector): Wrapper | ErrorWrapper { const nodes = findAll(this.vm, this.vnode, this.element, selector) @@ -273,20 +319,21 @@ export default class Wrapper implements BaseWrapper { if (selector.ref) { return new ErrorWrapper(`ref="${selector.ref}"`) } - return new ErrorWrapper(typeof selector === 'string' ? selector : 'Component') + return new ErrorWrapper( + typeof selector === 'string' ? selector : 'Component' + ) } return createWrapper(nodes[0], this.options) } /** - * Finds node in tree of the current wrapper that matches the provided selector. + * Finds node in tree of the current wrapper that matches + * the provided selector. */ findAll (selector: Selector): WrapperArray { getSelectorTypeOrThrow(selector, 'findAll') const nodes = findAll(this.vm, this.vnode, this.element, selector) - const wrappers = nodes.map(node => - createWrapper(node, this.options) - ) + const wrappers = nodes.map(node => createWrapper(node, this.options)) return new WrapperArray(wrappers) } @@ -328,9 +375,11 @@ export default class Wrapper implements BaseWrapper { return false } - return !!(this.element && - this.element.getAttribute && - this.element.matches(selector)) + return !!( + this.element && + this.element.getAttribute && + this.element.matches(selector) + ) } /** @@ -343,7 +392,9 @@ export default class Wrapper implements BaseWrapper { if (this.vnode.children) { return this.vnode.children.every(vnode => vnode.isComment) } - return this.vnode.children === undefined || this.vnode.children.length === 0 + return ( + this.vnode.children === undefined || this.vnode.children.length === 0 + ) } /** @@ -357,7 +408,11 @@ export default class Wrapper implements BaseWrapper { } while (element) { - if (element.style && (element.style.visibility === 'hidden' || element.style.display === 'none')) { + if ( + element.style && + (element.style.visibility === 'hidden' || + element.style.display === 'none') + ) { return false } element = element.parentElement @@ -393,20 +448,23 @@ export default class Wrapper implements BaseWrapper { */ props (): { [name: string]: any } { if (this.isFunctionalComponent) { - throwError('wrapper.props() cannot be called on a mounted functional component.') + throwError( + `wrapper.props() cannot be called on a mounted ` + + `functional component.` + ) } if (!this.vm) { throwError('wrapper.props() must be called on a Vue instance') } const props = {} - // $FlowIgnore - const keys = this.vm.$options._propKeys + const keys = this.vm && this.vm.$options._propKeys if (keys) { keys.forEach(key => { - // $FlowIgnore - props[key] = this.vm[key] + if (this.vm) { + props[key] = this.vm[key] + } }) } return props @@ -417,20 +475,33 @@ export default class Wrapper implements BaseWrapper { */ setData (data: Object) { if (this.isFunctionalComponent) { - throwError('wrapper.setData() cannot be called on a functional component') + throwError( + `wrapper.setData() cannot be called on a functional ` + + `component` + ) } if (!this.vm) { - throwError('wrapper.setData() can only be called on a Vue instance') - } - - Object.keys(data).forEach((key) => { - if (typeof data[key] === 'object' && data[key] !== null && - !Array.isArray(data[key])) { - // $FlowIgnore : Problem with possibly null this.vm - const newObj = mergeWith(this.vm[key], data[key], (objValue, srcValue) => { - return Array.isArray(srcValue) ? srcValue : undefined - }) + throwError( + `wrapper.setData() can only be called on a Vue ` + + `instance` + ) + } + + Object.keys(data).forEach(key => { + if ( + typeof data[key] === 'object' && + data[key] !== null && + !Array.isArray(data[key]) + ) { + const newObj = mergeWith( + // $FlowIgnore : Problem with possibly null this.vm + this.vm[key], + data[key], + (objValue, srcValue) => { + return Array.isArray(srcValue) ? srcValue : undefined + } + ) // $FlowIgnore : Problem with possibly null this.vm this.vm.$set(this.vm, [key], newObj) } else { @@ -445,16 +516,29 @@ export default class Wrapper implements BaseWrapper { */ setComputed (computed: Object) { if (!this.isVueInstance()) { - throwError('wrapper.setComputed() can only be called on a Vue instance') + 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') + 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) => { + Object.keys(computed).forEach(key => { if (this.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`) + 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] @@ -468,17 +552,25 @@ export default class Wrapper implements BaseWrapper { watcher.vm.$options.store.getters = { ...watcher.vm.$options.store.getters } - Object.defineProperty(watcher.vm.$options.store.getters, key, { get: function () { return computed[key] } }) + 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`) + 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) => { + this.vm._watchers.forEach(watcher => { if (watcher.getter.name === key) { watcher.value = computed[key] watcher.getter = () => computed[key] @@ -487,7 +579,7 @@ export default class Wrapper implements BaseWrapper { } }) // $FlowIgnore : Problem with possibly null this.vm - this.vm._watchers.forEach((watcher) => { + this.vm._watchers.forEach(watcher => { watcher.run() }) } @@ -497,9 +589,12 @@ export default class Wrapper implements BaseWrapper { */ setMethods (methods: Object) { if (!this.isVueInstance()) { - throwError('wrapper.setMethods() can only be called on a Vue instance') + throwError( + `wrapper.setMethods() can only be called on a Vue ` + + `instance` + ) } - Object.keys(methods).forEach((key) => { + Object.keys(methods).forEach(key => { // $FlowIgnore : Problem with possibly null this.vm this.vm[key] = methods[key] // $FlowIgnore : Problem with possibly null this.vm @@ -519,22 +614,31 @@ export default class Wrapper implements BaseWrapper { const originalConfig = Vue.config.silent Vue.config.silent = config.silentWarnings if (this.isFunctionalComponent) { - throwError('wrapper.setProps() cannot be called on a functional component') + throwError( + `wrapper.setProps() cannot be called on a ` + + `functional component` + ) } if (!this.isVm) { - throwError('wrapper.setProps() can only be called on a Vue instance') - } - - Object.keys(data).forEach((key) => { - // Ignore properties that were not specified in the component options - // $FlowIgnore : Problem with possibly null this.vm - if (!this.vm.$options._propKeys || - !this.vm.$options._propKeys.some(prop => prop === key)) { - throwError(`wrapper.setProps() called with ${key} property which is not defined on component`) + throwError( + `wrapper.setProps() can only be called on a Vue ` + + `instance` + ) + } + + Object.keys(data).forEach(key => { + if ( + !this.vm || + !this.vm.$options._propKeys || + !this.vm.$options._propKeys.some(prop => prop === key) + ) { + throwError( + `wrapper.setProps() called with ${key} property which ` + + `is not defined on the component` + ) } - // $FlowIgnore : Problem with possibly null this.vm - if (this.vm._props) { + if (this.vm && this.vm._props) { this.vm._props[key] = data[key] } else { // $FlowIgnore : Problem with possibly null this.vm @@ -557,7 +661,9 @@ export default class Wrapper implements BaseWrapper { const el = this.element if (!el) { - throwError('cannot call wrapper.setValue() on a wrapper without an element') + throwError( + `cannot call wrapper.setValue() on a wrapper ` + `without an element` + ) } const tag = el.tagName @@ -565,17 +671,28 @@ export default class Wrapper implements BaseWrapper { const event = 'input' if (tag === 'SELECT') { - throwError('wrapper.setValue() cannot be called on a ` + + `element. Use wrapper.setSelected() instead` + ) } else if (tag === 'INPUT' && type === 'checkbox') { - throwError('wrapper.setValue() cannot be called on a element. Use wrapper.setChecked() instead') + throwError( + `wrapper.setValue() cannot be called on a element. Use ` + + `wrapper.setChecked() instead` + ) } else if (tag === 'INPUT' && type === 'radio') { - throwError('wrapper.setValue() cannot be called on a element. Use wrapper.setChecked() instead') + throwError( + `wrapper.setValue() cannot be called on a element. Use wrapper.setChecked() ` + + `instead` + ) } else if (tag === 'INPUT' || tag === 'textarea') { // $FlowIgnore el.value = value this.trigger(event) } else { - throwError('wrapper.setValue() cannot be called on this element') + throwError(`wrapper.setValue() cannot be called on this ` + `element`) } } @@ -590,7 +707,9 @@ export default class Wrapper implements BaseWrapper { const el = this.element if (!el) { - throwError('cannot call wrapper.setChecked() on a wrapper without an element') + throwError( + `cannot call wrapper.setChecked() on a wrapper ` + `without an element` + ) } const tag = el.tagName @@ -598,7 +717,11 @@ export default class Wrapper implements BaseWrapper { const event = 'change' if (tag === 'SELECT') { - throwError('wrapper.setChecked() cannot be called on a element. Use wrapper.setSelected() ` + + `instead` + ) } else if (tag === 'INPUT' && type === 'checkbox') { // $FlowIgnore if (el.checked !== checked) { @@ -611,7 +734,11 @@ export default class Wrapper implements BaseWrapper { } } else if (tag === 'INPUT' && type === 'radio') { if (!checked) { - throwError('wrapper.setChecked() cannot be called with parameter false on a element.') + throwError( + `wrapper.setChecked() cannot be called with ` + + `parameter false on a ` + + `element.` + ) } else { // $FlowIgnore if (!el.checked) { @@ -620,9 +747,12 @@ export default class Wrapper implements BaseWrapper { } } } else if (tag === 'INPUT' || tag === 'textarea') { - throwError('wrapper.setChecked() cannot be called on "text" inputs. Use wrapper.setValue() instead') + throwError( + `wrapper.setChecked() cannot be called on "text" ` + + `inputs. Use wrapper.setValue() instead` + ) } else { - throwError('wrapper.setChecked() cannot be called on this element') + throwError(`wrapper.setChecked() cannot be called on this ` + `element`) } } @@ -633,7 +763,9 @@ export default class Wrapper implements BaseWrapper { const el = this.element if (!el) { - throwError('cannot call wrapper.setSelected() on a wrapper without an element') + throwError( + `cannot call wrapper.setSelected() on a wrapper ` + `without an element` + ) } const tag = el.tagName @@ -646,21 +778,37 @@ export default class Wrapper implements BaseWrapper { // $FlowIgnore if (el.parentElement.tagName === 'OPTGROUP') { // $FlowIgnore - createWrapper(el.parentElement.parentElement, this.options).trigger(event) + createWrapper(el.parentElement.parentElement, this.options).trigger( + event + ) } else { // $FlowIgnore createWrapper(el.parentElement, this.options).trigger(event) } } else if (tag === 'SELECT') { - throwError('wrapper.setSelected() cannot be called on select. Call it on one of its options') + throwError( + `wrapper.setSelected() cannot be called on select. ` + + `Call it on one of its options` + ) } else if (tag === 'INPUT' && type === 'checkbox') { - throwError('wrapper.setSelected() cannot be called on a element. Use wrapper.setChecked() instead') + throwError( + `wrapper.setSelected() cannot be called on a element. Use ` + + `wrapper.setChecked() instead` + ) } else if (tag === 'INPUT' && type === 'radio') { - throwError('wrapper.setSelected() cannot be called on a element. Use wrapper.setChecked() instead') + throwError( + `wrapper.setSelected() cannot be called on a element. Use wrapper.setChecked() ` + + `instead` + ) } else if (tag === 'INPUT' || tag === 'textarea') { - throwError('wrapper.setSelected() cannot be called on "text" inputs. Use wrapper.setValue() instead') + throwError( + `wrapper.setSelected() cannot be called on "text" ` + + `inputs. Use wrapper.setValue() instead` + ) } else { - throwError('wrapper.setSelected() cannot be called on this element') + throwError(`wrapper.setSelected() cannot be called on this ` + `element`) } } @@ -669,7 +817,9 @@ export default class Wrapper implements BaseWrapper { */ text (): string { if (!this.element) { - throwError('cannot call wrapper.text() on a wrapper without an element') + throwError( + `cannot call wrapper.text() on a wrapper without an ` + `element` + ) } return this.element.textContent.trim() @@ -680,7 +830,7 @@ export default class Wrapper implements BaseWrapper { */ destroy () { if (!this.isVueInstance()) { - throwError('wrapper.destroy() can only be called on a Vue instance') + throwError(`wrapper.destroy() can only be called on a Vue ` + `instance`) } if (this.element.parentNode) { @@ -699,11 +849,17 @@ export default class Wrapper implements BaseWrapper { } if (!this.element) { - throwError('cannot call wrapper.trigger() on a wrapper without an element') + throwError( + `cannot call wrapper.trigger() on a wrapper without ` + `an element` + ) } if (options.target) { - throwError('you cannot set the target value of an event. See the notes section of the docs for more details—https://vue-test-utils.vuejs.org/api/wrapper/trigger.html') + throwError( + `you cannot set the target value of an event. See ` + + `the notes section of the docs for more ` + + `details—https://vue-test-utils.vuejs.org/api/wrapper/trigger.html` + ) } // Don't fire event on a disabled element @@ -734,7 +890,7 @@ export default class Wrapper implements BaseWrapper { let eventObject // Fallback for IE10,11 - https://stackoverflow.com/questions/26596123 - if (typeof (window.Event) === 'function') { + if (typeof window.Event === 'function') { eventObject = new window.Event(event[0], { bubbles: true, cancelable: true @@ -763,6 +919,9 @@ export default class Wrapper implements BaseWrapper { } update () { - warn('update has been removed from vue-test-utils. All updates are now synchronous by default') + warn( + `update has been removed from vue-test-utils. All ` + + `updates are now synchronous by default` + ) } } diff --git a/scripts/gen-release-note.js b/scripts/gen-release-note.js index df4dedd99..b535c5a3a 100755 --- a/scripts/gen-release-note.js +++ b/scripts/gen-release-note.js @@ -11,6 +11,8 @@ cc({ return pkg } } -}).pipe(fileStream).on('close', () => { - console.log(`Generated release note at ${file}`) }) + .pipe(fileStream) + .on('close', () => { + console.log(`Generated release note at ${file}`) + }) diff --git a/test/resources/test-mixin.js b/test/resources/test-mixin.js index 7ef804164..7121d96ae 100644 --- a/test/resources/test-mixin.js +++ b/test/resources/test-mixin.js @@ -1,4 +1,3 @@ export default { - created: function () { - } + created: function () {} } diff --git a/test/resources/utils.js b/test/resources/utils.js index 1ddc1bac0..eabb68c92 100644 --- a/test/resources/utils.js +++ b/test/resources/utils.js @@ -4,7 +4,9 @@ import Vue from 'vue' import { shallowMount, mount } from '~vue/test-utils' import { renderToString } from '~vue/server-test-utils' -export const vueVersion = Number(`${Vue.version.split('.')[0]}.${Vue.version.split('.')[1]}`) +export const vueVersion = Number( + `${Vue.version.split('.')[0]}.${Vue.version.split('.')[1]}` +) export const isRunningJSDOM = typeof navigator !== 'undefined' && @@ -26,12 +28,10 @@ export const functionalSFCsSupported = vueVersion > 2.4 export const scopedSlotsSupported = vueVersion > 2 -const shallowAndMount = process.env.TEST_ENV === 'node' - ? [] - : [mount, shallowMount] -const shallowMountAndRender = process.env.TEST_ENV === 'node' - ? [renderToString] - : [mount, shallowMount] +const shallowAndMount = + process.env.TEST_ENV === 'node' ? [] : [mount, shallowMount] +const shallowMountAndRender = + process.env.TEST_ENV === 'node' ? [renderToString] : [mount, shallowMount] export function describeWithShallowAndMount (spec, cb) { if (shallowAndMount.length > 0) { diff --git a/test/setup/webpack.test.config.js b/test/setup/webpack.test.config.js index a8f2aac6b..ac6ff0ce2 100644 --- a/test/setup/webpack.test.config.js +++ b/test/setup/webpack.test.config.js @@ -1,3 +1,5 @@ +/* eslint-disable max-len */ + const nodeExternals = require('webpack-node-externals') const webpack = require('webpack') const browser = process.env.TARGET === 'browser' @@ -38,7 +40,5 @@ module.exports = { fs: 'empty', module: 'empty' }, - plugins: [ - new webpack.EnvironmentPlugin(['TEST_ENV']) - ] + plugins: [new webpack.EnvironmentPlugin(['TEST_ENV'])] } diff --git a/test/specs/.eslintrc b/test/specs/.eslintrc index 0c5839ad5..f40b77186 100644 --- a/test/specs/.eslintrc +++ b/test/specs/.eslintrc @@ -6,5 +6,8 @@ "globals": { "expect": true, "sinon": true + }, + "rules": { + "max-len": 0 } } \ No newline at end of file diff --git a/test/specs/components/RouterLink.spec.js b/test/specs/components/RouterLink.spec.js index c3c617467..95c23da94 100644 --- a/test/specs/components/RouterLink.spec.js +++ b/test/specs/components/RouterLink.spec.js @@ -1,7 +1,7 @@ import { RouterLinkStub } from '~vue/test-utils' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('RouterLinkStub', (mountingMethod) => { +describeWithShallowAndMount('RouterLinkStub', mountingMethod => { it('takes correct props', () => { const TestComponent = { template: ` diff --git a/test/specs/components/TransitionGroupStub.spec.js b/test/specs/components/TransitionGroupStub.spec.js index e2495dd80..99fab3d9b 100644 --- a/test/specs/components/TransitionGroupStub.spec.js +++ b/test/specs/components/TransitionGroupStub.spec.js @@ -2,7 +2,7 @@ import ComponentWithTransitionGroup from '~resources/components/component-with-t import { TransitionGroupStub } from '~vue/test-utils' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('TransitionGroupStub', (mountingMethod) => { +describeWithShallowAndMount('TransitionGroupStub', mountingMethod => { it('update synchronously when used as stubs for Transition', () => { const wrapper = mountingMethod(ComponentWithTransitionGroup, { stubs: { diff --git a/test/specs/components/TransitionStub.spec.js b/test/specs/components/TransitionStub.spec.js index 829bac1f8..a8331cba8 100644 --- a/test/specs/components/TransitionStub.spec.js +++ b/test/specs/components/TransitionStub.spec.js @@ -2,7 +2,7 @@ import ComponentWithTransition from '~resources/components/component-with-transi import { describeWithShallowAndMount } from '~resources/utils' import { TransitionStub } from '~vue/test-utils' -describeWithShallowAndMount('TransitionStub', (mountingMethod) => { +describeWithShallowAndMount('TransitionStub', mountingMethod => { let consoleError beforeEach(() => { @@ -16,7 +16,7 @@ describeWithShallowAndMount('TransitionStub', (mountingMethod) => { it('update synchronously when used as stubs for Transition', () => { const wrapper = mountingMethod(ComponentWithTransition, { stubs: { - 'transition': TransitionStub + transition: TransitionStub } }) expect(wrapper.text()).contains('a') @@ -40,7 +40,7 @@ describeWithShallowAndMount('TransitionStub', (mountingMethod) => { } const wrapper = mountingMethod(TestComponent, { stubs: { - 'transition': TransitionStub + transition: TransitionStub } }) expect(wrapper.find('nav').visible()).to.equal(false) @@ -56,10 +56,11 @@ describeWithShallowAndMount('TransitionStub', (mountingMethod) => {
` } - const msg = '[vue-test-utils]: can only be used on a single element. Use for lists.' + const msg = + '[vue-test-utils]: can only be used on a single element. Use for lists.' mountingMethod(TestComponent, { stubs: { - 'transition': TransitionStub + transition: TransitionStub } }) expect(consoleError).calledWith(msg) @@ -83,7 +84,7 @@ describeWithShallowAndMount('TransitionStub', (mountingMethod) => { } const wrapper = mountingMethod(TestComponent, { stubs: { - 'transition': TransitionStub + transition: TransitionStub } }) expect(wrapper.text()).to.equal('a') diff --git a/test/specs/config.spec.js b/test/specs/config.spec.js index 2e094ca7e..fb954342b 100644 --- a/test/specs/config.spec.js +++ b/test/specs/config.spec.js @@ -1,20 +1,16 @@ -import { - describeWithShallowAndMount, - vueVersion -} from '~resources/utils' +import { describeWithShallowAndMount, vueVersion } from '~resources/utils' import ComponentWithProps from '~resources/components/component-with-props.vue' +import { itDoNotRunIf, itSkipIf } from 'conditional-specs' import { - itDoNotRunIf, - itSkipIf -} from 'conditional-specs' -import { config, TransitionStub, TransitionGroupStub, createLocalVue } from '~vue/test-utils' + config, + TransitionStub, + TransitionGroupStub, + createLocalVue +} from '~vue/test-utils' import Vue from 'vue' -describeWithShallowAndMount('config', (mountingMethod) => { - let configStubsSave, - consoleError, - configLogSave, - configSilentWarningsSave +describeWithShallowAndMount('config', mountingMethod => { + let configStubsSave, consoleError, configLogSave, configSilentWarningsSave beforeEach(() => { TransitionGroupStub.name = 'another-temp-name' @@ -34,8 +30,10 @@ describeWithShallowAndMount('config', (mountingMethod) => { consoleError.restore() }) - itDoNotRunIf(mountingMethod.name === 'shallowMount', - 'stubs transition and transition-group by default', () => { + itDoNotRunIf( + mountingMethod.name === 'shallowMount', + 'stubs transition and transition-group by default', + () => { const testComponent = { template: `
@@ -47,7 +45,8 @@ describeWithShallowAndMount('config', (mountingMethod) => { const wrapper = mountingMethod(testComponent) expect(wrapper.contains(TransitionStub)).to.equal(true) expect(wrapper.contains(TransitionGroupStub)).to.equal(true) - }) + } + ) it('mocks a global variable', () => { const localVue = createLocalVue() @@ -63,7 +62,8 @@ describeWithShallowAndMount('config', (mountingMethod) => { config.mocks['$t'] = 'mock value' const wrapper = mountingMethod(testComponent, { - localVue, t + localVue, + t }) expect(wrapper.vm.$t).to.equal('mock value') @@ -87,7 +87,7 @@ describeWithShallowAndMount('config', (mountingMethod) => { expect(wrapper.text()).to.equal('method') }) - it('doesn\'t stub transition when config.stubs.transition is set to false', () => { + it("doesn't stub transition when config.stubs.transition is set to false", () => { const testComponent = { template: `
@@ -100,7 +100,7 @@ describeWithShallowAndMount('config', (mountingMethod) => { expect(wrapper.contains(TransitionStub)).to.equal(false) }) - it('doesn\'t stub transition when config.stubs.transition is set to false', () => { + it("doesn't stub transition when config.stubs.transition is set to false", () => { const testComponent = { template: `
@@ -113,7 +113,7 @@ describeWithShallowAndMount('config', (mountingMethod) => { expect(wrapper.contains(TransitionGroupStub)).to.equal(false) }) - it('doesn\'t stub transition when config.stubs is set to false', () => { + it("doesn't stub transition when config.stubs is set to false", () => { config.stubs = false const testComponent = { template: ` @@ -127,7 +127,7 @@ describeWithShallowAndMount('config', (mountingMethod) => { expect(wrapper.contains(TransitionStub)).to.equal(false) }) - it('doesn\'t stub transition when config.stubs is set to a string', () => { + it("doesn't stub transition when config.stubs is set to a string", () => { config.stubs = 'a string' const testComponent = { template: ` @@ -141,7 +141,7 @@ describeWithShallowAndMount('config', (mountingMethod) => { expect(wrapper.contains(TransitionStub)).to.equal(false) }) - it('doesn\'t throw Vue warning when silentWarnings is set to true', () => { + it("doesn't throw Vue warning when silentWarnings is set to true", () => { config.silentWarnings = true const localVue = createLocalVue() const wrapper = mountingMethod(ComponentWithProps, { @@ -175,7 +175,8 @@ describeWithShallowAndMount('config', (mountingMethod) => { itSkipIf( vueVersion < 2.3, - 'does not log when component is extended if logModifiedComponents is false', () => { + 'does not log when component is extended if logModifiedComponents is false', + () => { const ChildComponent = Vue.extend({ template: '' }) @@ -188,5 +189,6 @@ describeWithShallowAndMount('config', (mountingMethod) => { config.logModifiedComponents = false mountingMethod(TestComponent) expect(consoleError.called).to.equal(false) - }) + } + ) }) diff --git a/test/specs/create-local-vue.spec.js b/test/specs/create-local-vue.spec.js index 7e8501944..c1aac95f9 100644 --- a/test/specs/create-local-vue.spec.js +++ b/test/specs/create-local-vue.spec.js @@ -9,7 +9,7 @@ import ComponentWithRouter from '~resources/components/component-with-router.vue import { describeWithShallowAndMount } from '~resources/utils' import { itDoNotRunIf } from 'conditional-specs' -describeWithShallowAndMount('createLocalVue', (mountingMethod) => { +describeWithShallowAndMount('createLocalVue', mountingMethod => { it('installs Vuex without polluting global Vue', () => { const localVue = createLocalVue() localVue.use(Vuex) @@ -55,9 +55,7 @@ describeWithShallowAndMount('createLocalVue', (mountingMethod) => { it('installs Router without polluting global Vue', () => { const localVue = createLocalVue() localVue.use(VueRouter) - const routes = [ - { path: '/foo', component: Component } - ] + const routes = [{ path: '/foo', component: Component }] const router = new VueRouter({ routes }) @@ -69,7 +67,8 @@ describeWithShallowAndMount('createLocalVue', (mountingMethod) => { itDoNotRunIf( mountingMethod.name === 'shallowMount', - 'Router should work properly with local Vue', () => { + 'Router should work properly with local Vue', + () => { const localVue = createLocalVue() localVue.use(VueRouter) const routes = [ @@ -99,7 +98,8 @@ describeWithShallowAndMount('createLocalVue', (mountingMethod) => { const freshWrapper = mountingMethod(Component) expect(typeof freshWrapper.vm.$route).to.equal('undefined') - }) + } + ) it('use can take additional arguments', () => { const localVue = createLocalVue() diff --git a/test/specs/error-wrapper.spec.js b/test/specs/error-wrapper.spec.js index 043857701..1dd67a0cb 100644 --- a/test/specs/error-wrapper.spec.js +++ b/test/specs/error-wrapper.spec.js @@ -1,11 +1,37 @@ import { compileToFunctions } from 'vue-template-compiler' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('ErrorWrapper', (mountingMethod) => { - const methods = ['at', 'attributes', 'classes', 'contains', 'emitted', 'emittedByOrder', 'hasAttribute', - 'hasClass', 'hasProp', 'hasStyle', 'find', 'findAll', 'filter', 'html', 'text', 'is', 'isEmpty', 'isVisible', 'isVueInstance', - 'name', 'props', 'setComputed', 'setMethods', 'setData', 'setProps', 'trigger', 'destroy'] - methods.forEach((method) => { +describeWithShallowAndMount('ErrorWrapper', mountingMethod => { + const methods = [ + 'at', + 'attributes', + 'classes', + 'contains', + 'emitted', + 'emittedByOrder', + 'hasAttribute', + 'hasClass', + 'hasProp', + 'hasStyle', + 'find', + 'findAll', + 'filter', + 'html', + 'text', + 'is', + 'isEmpty', + 'isVisible', + 'isVueInstance', + 'name', + 'props', + 'setComputed', + 'setMethods', + 'setData', + 'setProps', + 'trigger', + 'destroy' + ] + methods.forEach(method => { it(`${method} throws error when called`, () => { const compiled = compileToFunctions('

') const selector = 'div' @@ -13,7 +39,9 @@ describeWithShallowAndMount('ErrorWrapper', (mountingMethod) => { const wrapper = mountingMethod(compiled) const error = wrapper.find(selector) expect(error.constructor.name).to.equal('ErrorWrapper') - expect(() => error[method]()).to.throw().with.property('message', message) + expect(() => error[method]()) + .to.throw() + .with.property('message', message) }) }) }) diff --git a/test/specs/mount.spec.js b/test/specs/mount.spec.js index b6564acf1..7f5b3f427 100644 --- a/test/specs/mount.spec.js +++ b/test/specs/mount.spec.js @@ -6,324 +6,333 @@ import ComponentWithProps from '~resources/components/component-with-props.vue' import ComponentWithMixin from '~resources/components/component-with-mixin.vue' import ComponentAsAClass from '~resources/components/component-as-a-class.vue' import { injectSupported, vueVersion } from '~resources/utils' -import { - describeRunIf, - itDoNotRunIf -} from 'conditional-specs' +import { describeRunIf, itDoNotRunIf } from 'conditional-specs' import Vuex from 'vuex' -describeRunIf(process.env.TEST_ENV !== 'node', - 'mount', () => { - const windowSave = window +describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => { + const windowSave = window - beforeEach(() => { - sinon.stub(console, 'error') - }) + beforeEach(() => { + sinon.stub(console, 'error') + }) - afterEach(() => { - window = windowSave // eslint-disable-line no-native-reassign - console.error.restore() - }) + afterEach(() => { + window = windowSave // eslint-disable-line no-native-reassign + console.error.restore() + }) - it('returns new VueWrapper with mounted Vue instance if no options are passed', () => { - const compiled = compileToFunctions('

') - const wrapper = mount(compiled) - expect(wrapper.vm).to.be.an('object') - }) + it('returns new VueWrapper with mounted Vue instance if no options are passed', () => { + const compiled = compileToFunctions('
') + const wrapper = mount(compiled) + expect(wrapper.vm).to.be.an('object') + }) - it('returns new VueWrapper with mounted Vue instance when root is functional component', () => { - const FunctionalComponent = { - functional: true, - render (h) { - return h('div', {}, [ - h('p', { - 'class': { - foo: true - } - }), - h('p') - ]) - }, - name: 'common' - } + it('returns new VueWrapper with mounted Vue instance when root is functional component', () => { + const FunctionalComponent = { + functional: true, + render (h) { + return h('div', {}, [ + h('p', { + class: { + foo: true + } + }), + h('p') + ]) + }, + name: 'common' + } - const wrapper = mount(FunctionalComponent) - expect(wrapper.findAll('p').length).to.equal(2) - }) + const wrapper = mount(FunctionalComponent) + expect(wrapper.findAll('p').length).to.equal(2) + }) - it('returns new VueWrapper with mounted Vue instance with props, if passed as propsData', () => { - const prop1 = { test: 'TEST' } - const wrapper = mount(ComponentWithProps, { propsData: { prop1 }}) - expect(wrapper.vm).to.be.an('object') - if (wrapper.vm.$props) { - expect(wrapper.vm.$props.prop1).to.equal(prop1) - } else { - expect(wrapper.vm.$options.propsData.prop1).to.equal(prop1) - } - }) + it('returns new VueWrapper with mounted Vue instance with props, if passed as propsData', () => { + const prop1 = { test: 'TEST' } + const wrapper = mount(ComponentWithProps, { propsData: { prop1 }}) + expect(wrapper.vm).to.be.an('object') + if (wrapper.vm.$props) { + expect(wrapper.vm.$props.prop1).to.equal(prop1) + } else { + expect(wrapper.vm.$options.propsData.prop1).to.equal(prop1) + } + }) - it('returns new VueWrapper with mounted Vue instance initialized with Vue.extend with props, if passed as propsData', () => { - const prop1 = { test: 'TEST' } - const TestComponent = Vue.extend(ComponentWithProps) - const wrapper = mount(TestComponent, { - propsData: { - prop1 - } - }) - expect(wrapper.vm).to.be.an('object') - if (wrapper.vm.$props) { - expect(wrapper.vm.$props.prop1).to.equal(prop1) - } else { - expect(wrapper.vm.$options.propsData.prop1).to.equal(prop1) + it('returns new VueWrapper with mounted Vue instance initialized with Vue.extend with props, if passed as propsData', () => { + const prop1 = { test: 'TEST' } + const TestComponent = Vue.extend(ComponentWithProps) + const wrapper = mount(TestComponent, { + propsData: { + prop1 } }) + expect(wrapper.vm).to.be.an('object') + if (wrapper.vm.$props) { + expect(wrapper.vm.$props.prop1).to.equal(prop1) + } else { + expect(wrapper.vm.$options.propsData.prop1).to.equal(prop1) + } + }) - it('handles uncompiled extended Vue component', () => { - const BaseComponent = { - template: '
' - } - const TestComponent = { - extends: BaseComponent - } - const wrapper = mount(TestComponent) - expect(wrapper.findAll('div').length).to.equal(1) - }) + it('handles uncompiled extended Vue component', () => { + const BaseComponent = { + template: '
' + } + const TestComponent = { + extends: BaseComponent + } + const wrapper = mount(TestComponent) + expect(wrapper.findAll('div').length).to.equal(1) + }) - it('handles nested uncompiled extended Vue component', () => { - const BaseComponent = { - template: '
' - } - const TestComponentA = { - extends: BaseComponent - } - const TestComponentB = { - extends: TestComponentA - } - const TestComponentC = { - extends: TestComponentB - } - const TestComponentD = { - extends: TestComponentC - } - const wrapper = mount(TestComponentD) - expect(wrapper.findAll('div').length).to.equal(1) - }) + it('handles nested uncompiled extended Vue component', () => { + const BaseComponent = { + template: '
' + } + const TestComponentA = { + extends: BaseComponent + } + const TestComponentB = { + extends: TestComponentA + } + const TestComponentC = { + extends: TestComponentB + } + const TestComponentD = { + extends: TestComponentC + } + const wrapper = mount(TestComponentD) + expect(wrapper.findAll('div').length).to.equal(1) + }) - it('does not use cached component', () => { - ComponentWithMixin.methods.someMethod = sinon.stub() - mount(ComponentWithMixin) - expect(ComponentWithMixin.methods.someMethod.callCount).to.equal(1) - ComponentWithMixin.methods.someMethod = sinon.stub() - mount(ComponentWithMixin) - expect(ComponentWithMixin.methods.someMethod.callCount).to.equal(1) - }) + it('does not use cached component', () => { + ComponentWithMixin.methods.someMethod = sinon.stub() + mount(ComponentWithMixin) + expect(ComponentWithMixin.methods.someMethod.callCount).to.equal(1) + ComponentWithMixin.methods.someMethod = sinon.stub() + mount(ComponentWithMixin) + expect(ComponentWithMixin.methods.someMethod.callCount).to.equal(1) + }) - it('throws an error if window is undefined', () => { - if (!(navigator.userAgent.includes && navigator.userAgent.includes('node.js'))) { - console.log('window read only. skipping test ...') - return - } + it('throws an error if window is undefined', () => { + if ( + !(navigator.userAgent.includes && navigator.userAgent.includes('node.js')) + ) { + console.log('window read only. skipping test ...') + return + } - const message = '[vue-test-utils]: window is undefined, vue-test-utils needs to be run in a browser environment.\n You can run the tests in node using JSDOM' - window = undefined // eslint-disable-line no-native-reassign + const message = + '[vue-test-utils]: window is undefined, vue-test-utils needs to be run in a browser environment.\n You can run the tests in node using JSDOM' + window = undefined // eslint-disable-line no-native-reassign - expect(() => mount(compileToFunctions('
'))).to.throw().with.property('message', message) - }) + expect(() => mount(compileToFunctions('
'))) + .to.throw() + .with.property('message', message) + }) - it('compiles inline templates', () => { - const wrapper = mount({ - template: `
foo
` - }) - expect(wrapper.vm).to.be.an('object') - expect(wrapper.html()).to.equal(`
foo
`) + it('compiles inline templates', () => { + const wrapper = mount({ + template: `
foo
` }) + expect(wrapper.vm).to.be.an('object') + expect(wrapper.html()).to.equal(`
foo
`) + }) - it('overrides methods', () => { - const stub = sinon.stub() - const TestComponent = Vue.extend({ - template: '
', - methods: { - callStub () { - stub() - } + it('overrides methods', () => { + const stub = sinon.stub() + const TestComponent = Vue.extend({ + template: '
', + methods: { + callStub () { + stub() } - }) - mount(TestComponent, { - methods: { - callStub () {} - } - }).vm.callStub() - - expect(stub).not.called + } }) + mount(TestComponent, { + methods: { + callStub () {} + } + }).vm.callStub() - // Problems accessing options of twice extended components in Vue < 2.3 - itDoNotRunIf(vueVersion < 2.3, - 'compiles extended components', () => { - const TestComponent = Vue.component('test-component', { - template: '
' - }) - const wrapper = mount(TestComponent) - expect(wrapper.html()).to.equal(`
`) - }) + expect(stub).not.called + }) - it('logs if component is extended', () => { - const msg = '[vue-test-utils]: an extended child component ChildComponent has been modified to ensure it has the correct instance properties. This means it is not possible to find the component with a component selector. To find the component, you must stub it manually using the stubs mounting option.' - const ChildComponent = Vue.extend({ - template: '' - }) - const TestComponent = { - template: '', - components: { - ChildComponent - } - } - mount(TestComponent) - expect(console.error).calledWith(msg) + // Problems accessing options of twice extended components in Vue < 2.3 + itDoNotRunIf(vueVersion < 2.3, 'compiles extended components', () => { + const TestComponent = Vue.component('test-component', { + template: '
' }) + const wrapper = mount(TestComponent) + expect(wrapper.html()).to.equal(`
`) + }) - it('deletes mounting options before passing options to component', () => { - const wrapper = mount({ + it('logs if component is extended', () => { + const msg = + `[vue-test-utils]: an extended child component ChildComponent ` + + `has been modified to ensure it has the correct instance properties. ` + + `This means it is not possible to find the component with a component ` + + `selector. To find the component, you must stub it manually using the ` + + `stubs mounting option.` + const ChildComponent = Vue.extend({ + template: '' + }) + const TestComponent = { + template: '', + components: { + ChildComponent + } + } + mount(TestComponent) + expect(console.error).calledWith(msg) + }) + + it('deletes mounting options before passing options to component', () => { + const wrapper = mount( + { render: h => h('div') - }, { + }, + { provide: { - 'prop': 'val' + prop: 'val' }, attachToDocument: 'attachToDocument', mocks: { - 'prop': 'val' + prop: 'val' }, slots: { - 'prop': Component + prop: Component }, localVue: createLocalVue(), stubs: { - 'prop': 'val' + prop: 'val' }, attrs: { - 'prop': 'val' + prop: 'val' }, listeners: { - 'prop': 'val' + prop: 'val' } - }) - if (injectSupported) { - expect(typeof wrapper.vm.$options.provide).to.equal('object') } + ) + if (injectSupported) { + expect(typeof wrapper.vm.$options.provide).to.equal('object') + } - expect(wrapper.vm.$options.attachToDocument).to.equal(undefined) - expect(wrapper.vm.$options.mocks).to.equal(undefined) - expect(wrapper.vm.$options.slots).to.equal(undefined) - expect(wrapper.vm.$options.localVue).to.equal(undefined) - expect(wrapper.vm.$options.stubs).to.equal(undefined) - expect(wrapper.vm.$options.context).to.equal(undefined) - expect(wrapper.vm.$options.attrs).to.equal(undefined) - expect(wrapper.vm.$options.listeners).to.equal(undefined) - }) + expect(wrapper.vm.$options.attachToDocument).to.equal(undefined) + expect(wrapper.vm.$options.mocks).to.equal(undefined) + expect(wrapper.vm.$options.slots).to.equal(undefined) + expect(wrapper.vm.$options.localVue).to.equal(undefined) + expect(wrapper.vm.$options.stubs).to.equal(undefined) + expect(wrapper.vm.$options.context).to.equal(undefined) + expect(wrapper.vm.$options.attrs).to.equal(undefined) + expect(wrapper.vm.$options.listeners).to.equal(undefined) + }) - it('injects store correctly', () => { - const localVue = createLocalVue() - localVue.use(Vuex) - const store = new Vuex.Store() - const wrapper = mount(ComponentAsAClass, { - store, - localVue - }) - wrapper.vm.getters - mount({ - template: '
{{$store.getters}}
' - }, { store, localVue }) + it('injects store correctly', () => { + const localVue = createLocalVue() + localVue.use(Vuex) + const store = new Vuex.Store() + const wrapper = mount(ComponentAsAClass, { + store, + localVue }) + wrapper.vm.getters + mount( + { + template: '
{{$store.getters}}
' + }, + { store, localVue } + ) + }) - it('propagates errors when they are thrown', () => { - const TestComponent = { - template: '
', - mounted: function () { - throw new Error('Error in mounted') - } + it('propagates errors when they are thrown', () => { + const TestComponent = { + template: '
', + mounted: function () { + throw new Error('Error in mounted') } + } - const fn = () => mount(TestComponent) - expect(fn).to.throw('Error in mounted') - }) + const fn = () => mount(TestComponent) + expect(fn).to.throw('Error in mounted') + }) - it('propagates errors when they are thrown by a nested component', () => { - const childComponent = { - template: '
', - mounted: function () { - throw new Error('Error in mounted') - } + it('propagates errors when they are thrown by a nested component', () => { + const childComponent = { + template: '
', + mounted: function () { + throw new Error('Error in mounted') } - const rootComponent = { - render: function (h) { - return h('div', [h(childComponent)]) - } + } + const rootComponent = { + render: function (h) { + return h('div', [h(childComponent)]) } + } - const fn = () => { - mount(rootComponent) - } + const fn = () => { + mount(rootComponent) + } - expect(fn).to.throw('Error in mounted') - }) - - itDoNotRunIf( - vueVersion < 2.2, - 'logs errors once after mount', (done) => { - Vue.config.errorHandler = null - const TestComponent = { - template: '
', - updated: function () { - throw new Error('Error in updated') - } - } - - const wrapper = mount(TestComponent, { - sync: false - }) - wrapper.vm.$forceUpdate() - setTimeout(() => { - vueVersion > 2.1 - ? expect(console.error).calledTwice - : expect(console.error).calledOnce - done() - }) - }) + expect(fn).to.throw('Error in mounted') + }) - it('restores user error handler after mount', () => { - const existingErrorHandler = () => {} - Vue.config.errorHandler = existingErrorHandler - const TestComponent = { - template: '
' + itDoNotRunIf(vueVersion < 2.2, 'logs errors once after mount', done => { + Vue.config.errorHandler = null + const TestComponent = { + template: '
', + updated: function () { + throw new Error('Error in updated') } - mount(TestComponent) - expect(Vue.config.errorHandler).to.equal(existingErrorHandler) - Vue.config.errorHandler = null + } + + const wrapper = mount(TestComponent, { + sync: false + }) + wrapper.vm.$forceUpdate() + setTimeout(() => { + vueVersion > 2.1 + ? expect(console.error).calledTwice + : expect(console.error).calledOnce + done() }) + }) + + it('restores user error handler after mount', () => { + const existingErrorHandler = () => {} + Vue.config.errorHandler = existingErrorHandler + const TestComponent = { + template: '
' + } + mount(TestComponent) + expect(Vue.config.errorHandler).to.equal(existingErrorHandler) + Vue.config.errorHandler = null + }) - it('overwrites the component options with the instance options', () => { - const Component = { - template: '
{{ foo() }}{{ bar() }}{{ baz() }}
', - methods: { - foo () { - return 'a' - }, - bar () { - return 'b' - } + it('overwrites the component options with the instance options', () => { + const Component = { + template: '
{{ foo() }}{{ bar() }}{{ baz() }}
', + methods: { + foo () { + return 'a' + }, + bar () { + return 'b' } } - const options = { - methods: { - bar () { - return 'B' - }, - baz () { - return 'C' - } + } + const options = { + methods: { + bar () { + return 'B' + }, + baz () { + return 'C' } } - const wrapper = mount(Component, options) - expect(wrapper.text()).to.equal('aBC') - }) + } + const wrapper = mount(Component, options) + expect(wrapper.text()).to.equal('aBC') }) +}) diff --git a/test/specs/mounting-options/attachToDocument.spec.js b/test/specs/mounting-options/attachToDocument.spec.js index de588f56f..3c12b5bf1 100644 --- a/test/specs/mounting-options/attachToDocument.spec.js +++ b/test/specs/mounting-options/attachToDocument.spec.js @@ -1,11 +1,8 @@ import { compileToFunctions } from 'vue-template-compiler' -import { - describeWithShallowAndMount, - isRunningJSDOM -} from '~resources/utils' +import { describeWithShallowAndMount, isRunningJSDOM } from '~resources/utils' import { renderToString } from '@vue/server-test-utils' -describeWithShallowAndMount('options.attachToDocument', (mountingMethod) => { +describeWithShallowAndMount('options.attachToDocument', mountingMethod => { it('returns VueWrapper with attachedToDocument set to true when passed attachToDocument in options', () => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled, { attachToDocument: true }) @@ -21,7 +18,10 @@ describe('options.attachToDocument with renderToString', () => { } const compiled = compileToFunctions('
') const fn = () => renderToString(compiled, { attachToDocument: true }) - const message = '[vue-test-utils]: you cannot use attachToDocument with renderToString' - expect(fn).to.throw().with.property('message', message) + const message = + '[vue-test-utils]: you cannot use attachToDocument with renderToString' + expect(fn) + .to.throw() + .with.property('message', message) }) }) diff --git a/test/specs/mounting-options/attrs.spec.js b/test/specs/mounting-options/attrs.spec.js index 92f7e878a..cb6ba5de7 100644 --- a/test/specs/mounting-options/attrs.spec.js +++ b/test/specs/mounting-options/attrs.spec.js @@ -5,17 +5,15 @@ import { isRunningPhantomJS, vueVersion } from '~resources/utils' -import { - itSkipIf, - itDoNotRunIf -} from 'conditional-specs' +import { itSkipIf, itDoNotRunIf } from 'conditional-specs' -describeWithMountingMethods('options.attrs', (mountingMethod) => { +describeWithMountingMethods('options.attrs', mountingMethod => { itDoNotRunIf( vueVersion < 2.4 || - mountingMethod.name === 'renderToString' || - isRunningPhantomJS, - 'handles inherit attrs', () => { + mountingMethod.name === 'renderToString' || + isRunningPhantomJS, + 'handles inherit attrs', + () => { if (!attrsSupported) return const wrapper = mountingMethod(compileToFunctions('

'), { attrs: { @@ -24,13 +22,15 @@ describeWithMountingMethods('options.attrs', (mountingMethod) => { }) expect(wrapper.vm.$attrs.anAttr).to.equal('an attribute') expect(wrapper.vm.$attrs.anAttr).to.equal('an attribute') - }) + } + ) itSkipIf( - mountingMethod.name === 'renderToString' || - vueVersion < 2.5, - 'defines attrs as empty object even when not passed', () => { + mountingMethod.name === 'renderToString' || vueVersion < 2.5, + 'defines attrs as empty object even when not passed', + () => { const wrapper = mountingMethod(compileToFunctions('

')) expect(wrapper.vm.$attrs).to.deep.equal({}) - }) + } + ) }) diff --git a/test/specs/mounting-options/context.spec.js b/test/specs/mounting-options/context.spec.js index 8c1cac024..134cbef75 100644 --- a/test/specs/mounting-options/context.spec.js +++ b/test/specs/mounting-options/context.spec.js @@ -2,10 +2,12 @@ import Vue from 'vue' import { vueVersion } from '~resources/utils' import { describeWithMountingMethods } from '~resources/utils' -describeWithMountingMethods('options.context', (mountingMethod) => { +describeWithMountingMethods('options.context', mountingMethod => { it('mounts functional component when passed context object', () => { if (vueVersion <= 2.2) { - console.log('WARN: no current way to test functional component in vue@2.1') + console.log( + 'WARN: no current way to test functional component in vue@2.1' + ) return } @@ -29,9 +31,12 @@ describeWithMountingMethods('options.context', (mountingMethod) => { render: h => h('div') } const context = {} - const message = '[vue-test-utils]: mount.context can only be used when mounting a functional component' + const message = + '[vue-test-utils]: mount.context can only be used when mounting a functional component' const fn = () => mountingMethod(Component, { context }) - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) }) it('does not throw error if functional component with Vue.extend', () => { @@ -52,7 +57,9 @@ describeWithMountingMethods('options.context', (mountingMethod) => { const context = 'string' const message = '[vue-test-utils]: mount.context must be an object' const fn = () => mountingMethod(Component, { context }) - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) }) it('mounts functional component with a defined context when no context object passed in options', () => { @@ -68,9 +75,8 @@ describeWithMountingMethods('options.context', (mountingMethod) => { render: (h, { props }) => h('div', props.testProp) } const wrapper = mountingMethod(Component) - const HTML = mountingMethod.name === 'renderToString' - ? wrapper - : wrapper.html() + const HTML = + mountingMethod.name === 'renderToString' ? wrapper : wrapper.html() expect(HTML).to.contain(defaultValue) }) @@ -86,9 +92,8 @@ describeWithMountingMethods('options.context', (mountingMethod) => { children: ['render text'] } }) - const HTML = mountingMethod.name === 'renderToString' - ? wrapper - : wrapper.html() + const HTML = + mountingMethod.name === 'renderToString' ? wrapper : wrapper.html() expect(HTML).to.contain('render text') }) @@ -104,9 +109,8 @@ describeWithMountingMethods('options.context', (mountingMethod) => { children: [h => h('div', 'render component')] } }) - const HTML = mountingMethod.name === 'renderToString' - ? wrapper - : wrapper.html() + const HTML = + mountingMethod.name === 'renderToString' ? wrapper : wrapper.html() expect(HTML).to.contain('render component') }) }) diff --git a/test/specs/mounting-options/listeners.spec.js b/test/specs/mounting-options/listeners.spec.js index 426aca4d8..dcf469542 100644 --- a/test/specs/mounting-options/listeners.spec.js +++ b/test/specs/mounting-options/listeners.spec.js @@ -5,29 +5,31 @@ import { isRunningPhantomJS, vueVersion } from '~resources/utils' -import { - itDoNotRunIf -} from 'conditional-specs' +import { itDoNotRunIf } from 'conditional-specs' -describeWithShallowAndMount('options.listeners', (mountingMethod) => { - itDoNotRunIf( - isRunningPhantomJS, - 'handles inherit listeners', () => { - if (!listenersSupported) return - const aListener = () => {} - const wrapper = mountingMethod(compileToFunctions('

'), { +describeWithShallowAndMount('options.listeners', mountingMethod => { + itDoNotRunIf(isRunningPhantomJS, 'handles inherit listeners', () => { + if (!listenersSupported) return + const aListener = () => {} + const wrapper = mountingMethod( + compileToFunctions('

'), + { listeners: { aListener } - }) + } + ) - expect(wrapper.vm.$listeners.aListener.fns).to.equal(aListener) - expect(wrapper.vm.$listeners.aListener.fns).to.equal(aListener) - }) + expect(wrapper.vm.$listeners.aListener.fns).to.equal(aListener) + expect(wrapper.vm.$listeners.aListener.fns).to.equal(aListener) + }) - itDoNotRunIf(vueVersion < 2.5, - 'defines listeners as empty object even when not passed', () => { + itDoNotRunIf( + vueVersion < 2.5, + 'defines listeners as empty object even when not passed', + () => { const wrapper = mountingMethod(compileToFunctions('

')) expect(wrapper.vm.$listeners).to.deep.equal({}) - }) + } + ) }) diff --git a/test/specs/mounting-options/localVue.spec.js b/test/specs/mounting-options/localVue.spec.js index bb1c2fe30..9fbf2bb26 100644 --- a/test/specs/mounting-options/localVue.spec.js +++ b/test/specs/mounting-options/localVue.spec.js @@ -8,10 +8,11 @@ import { createLocalVue } from '~vue/test-utils' import { itSkipIf } from 'conditional-specs' import Vuex from 'vuex' -describeWithMountingMethods('options.localVue', (mountingMethod) => { +describeWithMountingMethods('options.localVue', mountingMethod => { itSkipIf( isRunningPhantomJS, - 'mounts component using passed localVue as base Vue', () => { + 'mounts component using passed localVue as base Vue', + () => { const TestComponent = { template: `

{{test}}
@@ -24,50 +25,48 @@ describeWithMountingMethods('options.localVue', (mountingMethod) => { localVue: localVue, mocks: { test: 'some value' } }) - const HTML = mountingMethod.name === 'renderToString' - ? wrapper - : wrapper.html() + const HTML = + mountingMethod.name === 'renderToString' ? wrapper : wrapper.html() expect(HTML).to.contain('some value') const freshWrapper = mountingMethod(TestComponent) - const freshHTML = mountingMethod.name === 'renderToString' - ? freshWrapper - : freshWrapper.html() + const freshHTML = + mountingMethod.name === 'renderToString' + ? freshWrapper + : freshWrapper.html() expect(freshHTML).to.not.contain('some value') - }) + } + ) - itSkipIf( - vueVersion < 2.3, - 'works correctly with extended children', () => { - const localVue = createLocalVue() - localVue.use(Vuex) - const store = new Vuex.Store({ - state: { val: 2 } - }) - const ChildComponent = Vue.extend({ - template: '{{val}}', - computed: { - val () { - return this.$store.state.val - } - } - }) - const TestComponent = { - template: '
', - components: { - ChildComponent + itSkipIf(vueVersion < 2.3, 'works correctly with extended children', () => { + const localVue = createLocalVue() + localVue.use(Vuex) + const store = new Vuex.Store({ + state: { val: 2 } + }) + const ChildComponent = Vue.extend({ + template: '{{val}}', + computed: { + val () { + return this.$store.state.val } } - const wrapper = mountingMethod(TestComponent, { - localVue, - store - }) - const HTML = mountingMethod.name === 'renderToString' - ? wrapper - : wrapper.html() - if (mountingMethod.name === 'shallowMount') { - expect(HTML).to.not.contain('2') - } else { - expect(HTML).to.contain('2') + }) + const TestComponent = { + template: '
', + components: { + ChildComponent } + } + const wrapper = mountingMethod(TestComponent, { + localVue, + store }) + const HTML = + mountingMethod.name === 'renderToString' ? wrapper : wrapper.html() + if (mountingMethod.name === 'shallowMount') { + expect(HTML).to.not.contain('2') + } else { + expect(HTML).to.contain('2') + } + }) }) diff --git a/test/specs/mounting-options/methods.spec.js b/test/specs/mounting-options/methods.spec.js index 8ee1306c8..04524c1ee 100644 --- a/test/specs/mounting-options/methods.spec.js +++ b/test/specs/mounting-options/methods.spec.js @@ -1,9 +1,7 @@ import { config } from '~vue/test-utils' -import { - describeWithMountingMethods -} from '~resources/utils' +import { describeWithMountingMethods } from '~resources/utils' -describeWithMountingMethods('options.methods', (mountingMethod) => { +describeWithMountingMethods('options.methods', mountingMethod => { it('prioritize mounting options over config', () => { config.methods['val'] = () => 'methodFromConfig' @@ -20,9 +18,8 @@ describeWithMountingMethods('options.methods', (mountingMethod) => { } } }) - const HTML = mountingMethod.name === 'renderToString' - ? wrapper - : wrapper.html() + const HTML = + mountingMethod.name === 'renderToString' ? wrapper : wrapper.html() expect(HTML).to.contain('methodFromOptions') }) }) diff --git a/test/specs/mounting-options/mocks.spec.js b/test/specs/mounting-options/mocks.spec.js index 451e9de4e..34291f830 100644 --- a/test/specs/mounting-options/mocks.spec.js +++ b/test/specs/mounting-options/mocks.spec.js @@ -4,19 +4,18 @@ import ComponentWithVuex from '~resources/components/component-with-vuex.vue' import { describeWithMountingMethods } from '~resources/utils' import { itDoNotRunIf } from 'conditional-specs' -describeWithMountingMethods('options.mocks', (mountingMethod) => { +describeWithMountingMethods('options.mocks', mountingMethod => { let configMocksSave - let consoleError beforeEach(() => { configMocksSave = config.mocks config.mocks = {} - consoleError = sinon.stub(console, 'error') + sinon.stub(console, 'error') }) afterEach(() => { config.mocks = configMocksSave - consoleError.restore() + console.error.restore() }) it('adds variables to vm when passed', () => { @@ -36,80 +35,97 @@ describeWithMountingMethods('options.mocks', (mountingMethod) => { $route } }) - const HTML = mountingMethod.name === 'renderToString' - ? wrapper - : wrapper.html() + const HTML = + mountingMethod.name === 'renderToString' ? wrapper : wrapper.html() expect(HTML).contains('true') expect(HTML).contains('http://test.com') }) // render returns a string so reactive does not apply - itDoNotRunIf(mountingMethod.name === 'renderToString', - 'adds variables as reactive properties to vm when passed', () => { + itDoNotRunIf( + mountingMethod.name === 'renderToString', + 'adds variables as reactive properties to vm when passed', + () => { const stub = sinon.stub() const $reactiveMock = { value: 'value' } - const wrapper = mountingMethod({ - template: ` + const wrapper = mountingMethod( + { + template: `
{{value}}
`, - computed: { - value () { - return this.$reactiveMock.value + computed: { + value () { + return this.$reactiveMock.value + } + }, + watch: { + value () { + stub() + } } }, - watch: { - value () { - stub() - } + { + mocks: { $reactiveMock } } - }, { - mocks: { $reactiveMock } - }) + ) expect(wrapper.text()).to.contain('value') $reactiveMock.value = 'changed value' expect(wrapper.text()).to.contain('changed value') - }) + } + ) - itDoNotRunIf(mountingMethod.name === 'shallowMount', - 'adds variables available to nested vms', () => { + itDoNotRunIf( + mountingMethod.name === 'shallowMount', + 'adds variables available to nested vms', + () => { const count = 1 - const wrapper = mountingMethod({ - template: '
', - components: { - ComponentWithVuex + const wrapper = mountingMethod( + { + template: '
', + components: { + ComponentWithVuex + } + }, + { + mocks: { $store: { state: { count, foo: {}}}} } - }, { - mocks: { $store: { state: { count, foo: {}}}} - }) - const HTML = mountingMethod.name === 'renderToString' - ? wrapper - : wrapper.html() + ) + const HTML = + mountingMethod.name === 'renderToString' ? wrapper : wrapper.html() expect(HTML).contains(count) - }) + } + ) - itDoNotRunIf(mountingMethod.name === 'shallowMount', - 'adds variables available to nested vms using localVue', () => { + itDoNotRunIf( + mountingMethod.name === 'shallowMount', + 'adds variables available to nested vms using localVue', + () => { const localVue = createLocalVue() const count = 1 - const wrapper = mountingMethod({ - template: '
', - components: { - ComponentWithVuex + const wrapper = mountingMethod( + { + template: '
', + components: { + ComponentWithVuex + } + }, + { + mocks: { $store: { state: { count, foo: {}}}}, + localVue } - }, { - mocks: { $store: { state: { count, foo: {}}}}, - localVue - }) - const HTML = mountingMethod.name === 'renderToString' - ? wrapper - : wrapper.html() + ) + const HTML = + mountingMethod.name === 'renderToString' ? wrapper : wrapper.html() expect(HTML).contains(count) - }) + } + ) - itDoNotRunIf(mountingMethod.name === 'renderToString', - 'does not affect global vue class when passed as mocks object', () => { + itDoNotRunIf( + mountingMethod.name === 'renderToString', + 'does not affect global vue class when passed as mocks object', + () => { const $store = { store: true } const wrapper = mountingMethod(Component, { mocks: { @@ -119,7 +135,8 @@ describeWithMountingMethods('options.mocks', (mountingMethod) => { expect(wrapper.vm.$store).to.equal($store) const freshWrapper = mountingMethod(Component) expect(typeof freshWrapper.vm.$store).to.equal('undefined') - }) + } + ) it('logs that a property cannot be overwritten if there are problems writing', () => { const localVue = createLocalVue() @@ -133,8 +150,11 @@ describeWithMountingMethods('options.mocks', (mountingMethod) => { $store } }) - const msg = '[vue-test-utils]: could not overwrite property $store, this usually caused by a plugin that has added the property as a read-only value' - expect(consoleError.calledWith(msg)).to.equal(true) + const msg = + `[vue-test-utils]: could not overwrite property $store, this ` + + `is usually caused by a plugin that has added the property as ` + + `a read-only value` + expect(console.error).calledWith(msg) }) it('prioritize mounting options over config', () => { @@ -148,28 +168,11 @@ describeWithMountingMethods('options.mocks', (mountingMethod) => { const wrapper = mountingMethod(TestComponent, { mocks: { - '$global': 'locallyMockedValue' + $global: 'locallyMockedValue' } }) - const HTML = mountingMethod.name === 'renderToString' - ? wrapper - : wrapper.html() + const HTML = + mountingMethod.name === 'renderToString' ? wrapper : wrapper.html() expect(HTML).to.contain('locallyMockedValue') }) - - it('logs that a property cannot be overwritten if there are problems writing', () => { - const localVue = createLocalVue() - Object.defineProperty(localVue.prototype, '$val', { - value: 42 - }) - const $val = 64 - mountingMethod(Component, { - localVue, - mocks: { - $val - } - }) - const msg = '[vue-test-utils]: could not overwrite property $val, this usually caused by a plugin that has added the property as a read-only value' - expect(consoleError.calledWith(msg)).to.equal(true) - }) }) diff --git a/test/specs/mounting-options/propsData.spec.js b/test/specs/mounting-options/propsData.spec.js index 42ba93047..79c422927 100644 --- a/test/specs/mounting-options/propsData.spec.js +++ b/test/specs/mounting-options/propsData.spec.js @@ -6,29 +6,28 @@ const baseData = { prop1: ['', ''] } -describeRunIf(process.env.TEST_ENV !== 'node', - 'propsData', () => { - let wrapper +describeRunIf(process.env.TEST_ENV !== 'node', 'propsData', () => { + let wrapper - beforeEach(() => { - wrapper = shallowMount(ComponentWithProps, { - propsData: baseData - }) + beforeEach(() => { + wrapper = shallowMount(ComponentWithProps, { + propsData: baseData }) + }) - afterEach(() => { - wrapper = null - }) + afterEach(() => { + wrapper = null + }) - describe('should not modify propsData between tests', () => { - it('should have the correct props after modifying', () => { - expect(wrapper.vm.prop1).to.have.length(2) - wrapper.setProps({ prop1: [] }) - expect(wrapper.vm.prop1).to.have.length(0) - }) + describe('should not modify propsData between tests', () => { + it('should have the correct props after modifying', () => { + expect(wrapper.vm.prop1).to.have.length(2) + wrapper.setProps({ prop1: [] }) + expect(wrapper.vm.prop1).to.have.length(0) + }) - it('should have the default props despite being modified in the previous test', () => { - expect(wrapper.vm.prop1).to.have.length(2) - }) + it('should have the default props despite being modified in the previous test', () => { + expect(wrapper.vm.prop1).to.have.length(2) }) }) +}) diff --git a/test/specs/mounting-options/provide.spec.js b/test/specs/mounting-options/provide.spec.js index 9c9f61f96..0febe810d 100644 --- a/test/specs/mounting-options/provide.spec.js +++ b/test/specs/mounting-options/provide.spec.js @@ -2,12 +2,9 @@ import { config } from '~vue/test-utils' import ComponentWithInject from '~resources/components/component-with-inject.vue' import { injectSupported } from '~resources/utils' import { describeWithMountingMethods } from '~resources/utils' -import { - itDoNotRunIf, - itSkipIf -} from 'conditional-specs' +import { itDoNotRunIf, itSkipIf } from 'conditional-specs' -describeWithMountingMethods('options.provide', (mountingMethod) => { +describeWithMountingMethods('options.provide', mountingMethod => { let configProvideSave beforeEach(() => { @@ -19,21 +16,25 @@ describeWithMountingMethods('options.provide', (mountingMethod) => { config.provide = configProvideSave }) - itDoNotRunIf(!injectSupported, - 'provides objects which is injected by mounted component', () => { + itDoNotRunIf( + !injectSupported, + 'provides objects which is injected by mounted component', + () => { if (!injectSupported) return const wrapper = mountingMethod(ComponentWithInject, { provide: { fromMount: 'objectValue' } }) - const HTML = mountingMethod.name === 'renderToString' - ? wrapper - : wrapper.html() + const HTML = + mountingMethod.name === 'renderToString' ? wrapper : wrapper.html() expect(HTML).to.contain('objectValue') - }) + } + ) - itDoNotRunIf(!injectSupported, - 'provides function which is injected by mounted component', () => { + itDoNotRunIf( + !injectSupported, + 'provides function which is injected by mounted component', + () => { const wrapper = mountingMethod(ComponentWithInject, { provide () { return { @@ -41,14 +42,16 @@ describeWithMountingMethods('options.provide', (mountingMethod) => { } } }) - const HTML = mountingMethod.name === 'renderToString' - ? wrapper - : wrapper.html() + const HTML = + mountingMethod.name === 'renderToString' ? wrapper : wrapper.html() expect(HTML).to.contain('functionValue') - }) + } + ) - itDoNotRunIf(!injectSupported || mountingMethod.name === 'renderToString', - 'supports beforeCreate in component', () => { + itDoNotRunIf( + !injectSupported || mountingMethod.name === 'renderToString', + 'supports beforeCreate in component', + () => { if (!injectSupported) return const wrapper = mountingMethod(ComponentWithInject, { @@ -56,38 +59,46 @@ describeWithMountingMethods('options.provide', (mountingMethod) => { }) expect(wrapper.vm.setInBeforeCreate).to.equal('created') - }) + } + ) - itSkipIf(mountingMethod.name === 'renderToString', - 'injects the provide from the config', () => { + itSkipIf( + mountingMethod.name === 'renderToString', + 'injects the provide from the config', + () => { if (!injectSupported) { return } config.provide['fromMount'] = 'globalConfig' const wrapper = mountingMethod(ComponentWithInject) - const HTML = mountingMethod.name === 'renderToString' - ? wrapper - : wrapper.html() + const HTML = + mountingMethod.name === 'renderToString' ? wrapper : wrapper.html() expect(HTML).to.contain('globalConfig') - }) + } + ) - itDoNotRunIf(!injectSupported, 'prioritize mounting options over config', () => { - config.provide['fromMount'] = 'globalConfig' + itDoNotRunIf( + !injectSupported, + 'prioritize mounting options over config', + () => { + config.provide['fromMount'] = 'globalConfig' - const wrapper = mountingMethod(ComponentWithInject, { - provide: { fromMount: '_' } - }) - const HTML = mountingMethod.name === 'renderToString' - ? wrapper - : wrapper.html() + const wrapper = mountingMethod(ComponentWithInject, { + provide: { fromMount: '_' } + }) + const HTML = + mountingMethod.name === 'renderToString' ? wrapper : wrapper.html() - expect(HTML).to.contain('_') - }) + expect(HTML).to.contain('_') + } + ) - itSkipIf(mountingMethod.name === 'renderToString', - 'config with function throws', () => { + itSkipIf( + mountingMethod.name === 'renderToString', + 'config with function throws', + () => { config.provide = () => {} expect(() => { @@ -95,5 +106,6 @@ describeWithMountingMethods('options.provide', (mountingMethod) => { provide: { fromMount: '_' } }) }).to.throw() - }) + } + ) }) diff --git a/test/specs/mounting-options/scopedSlots.spec.js b/test/specs/mounting-options/scopedSlots.spec.js index d8294f72c..64d70944a 100644 --- a/test/specs/mounting-options/scopedSlots.spec.js +++ b/test/specs/mounting-options/scopedSlots.spec.js @@ -6,42 +6,67 @@ import { import ComponentWithScopedSlots from '~resources/components/component-with-scoped-slots.vue' import { itDoNotRunIf } from 'conditional-specs' -describeWithShallowAndMount('scopedSlots', (mountingMethod) => { +describeWithShallowAndMount('scopedSlots', mountingMethod => { const windowSave = window afterEach(() => { window = windowSave // eslint-disable-line no-native-reassign }) - itDoNotRunIf(vueVersion < 2.5 || isRunningPhantomJS, - 'mounts component scoped slots', () => { + itDoNotRunIf( + vueVersion < 2.5 || isRunningPhantomJS, + 'mounts component scoped slots', + () => { const wrapper = mountingMethod(ComponentWithScopedSlots, { slots: { default: '123' }, scopedSlots: { - destructuring: '

{{index}},{{item}}

', + destructuring: + '

{{index}},{{item}}

', list: '

{{foo.index}},{{foo.text}}

', single: '

{{bar.text}}

', noProps: '

baz

' } }) - expect(wrapper.find('#destructuring').html()).to.equal('

0,1

1,2

2,3

') - expect(wrapper.find('#slots').html()).to.equal('
123
') - expect(wrapper.find('#list').html()).to.equal('

0,a1

1,a2

2,a3

') - expect(wrapper.find('#single').html()).to.equal('

abc

') - expect(wrapper.find('#noProps').html()).to.equal('

baz

') + expect(wrapper.find('#destructuring').html()).to.equal( + '

0,1

1,2

2,3

' + ) + expect(wrapper.find('#slots').html()).to.equal( + '
123
' + ) + expect(wrapper.find('#list').html()).to.equal( + '

0,a1

1,a2

2,a3

' + ) + expect(wrapper.find('#single').html()).to.equal( + '

abc

' + ) + expect(wrapper.find('#noProps').html()).to.equal( + '

baz

' + ) wrapper.vm.items = [4, 5, 6] wrapper.vm.foo = [{ text: 'b1' }, { text: 'b2' }, { text: 'b3' }] wrapper.vm.bar = 'ABC' - expect(wrapper.find('#destructuring').html()).to.equal('

0,4

1,5

2,6

') - expect(wrapper.find('#slots').html()).to.equal('
123
') - expect(wrapper.find('#list').html()).to.equal('

0,b1

1,b2

2,b3

') - expect(wrapper.find('#single').html()).to.equal('

ABC

') - expect(wrapper.find('#noProps').html()).to.equal('

baz

') + expect(wrapper.find('#destructuring').html()).to.equal( + '

0,4

1,5

2,6

' + ) + expect(wrapper.find('#slots').html()).to.equal( + '
123
' + ) + expect(wrapper.find('#list').html()).to.equal( + '

0,b1

1,b2

2,b3

' + ) + expect(wrapper.find('#single').html()).to.equal( + '

ABC

' + ) + expect(wrapper.find('#noProps').html()).to.equal( + '

baz

' + ) } ) - itDoNotRunIf(vueVersion < 2.5 || isRunningPhantomJS, - 'throws exception when it is seted to a template tag at top', () => { + itDoNotRunIf( + vueVersion < 2.5 || isRunningPhantomJS, + 'throws exception when it is seted to a template tag at top', + () => { const fn = () => { mountingMethod(ComponentWithScopedSlots, { scopedSlots: { @@ -49,13 +74,18 @@ describeWithShallowAndMount('scopedSlots', (mountingMethod) => { } }) } - const message = '[vue-test-utils]: the scopedSlots option does not support a template tag as the root element.' - expect(fn).to.throw().with.property('message', message) + const message = + '[vue-test-utils]: the scopedSlots option does not support a template tag as the root element.' + expect(fn) + .to.throw() + .with.property('message', message) } ) - itDoNotRunIf(vueVersion >= 2.5 || isRunningPhantomJS, - 'throws exception when vue version < 2.5', () => { + itDoNotRunIf( + vueVersion >= 2.5 || isRunningPhantomJS, + 'throws exception when vue version < 2.5', + () => { const fn = () => { mountingMethod(ComponentWithScopedSlots, { scopedSlots: { @@ -63,13 +93,18 @@ describeWithShallowAndMount('scopedSlots', (mountingMethod) => { } }) } - const message = '[vue-test-utils]: the scopedSlots option is only supported in vue@2.5+.' - expect(fn).to.throw().with.property('message', message) + const message = + '[vue-test-utils]: the scopedSlots option is only supported in vue@2.5+.' + expect(fn) + .to.throw() + .with.property('message', message) } ) - itDoNotRunIf(vueVersion < 2.5, - 'throws exception when using PhantomJS', () => { + itDoNotRunIf( + vueVersion < 2.5, + 'throws exception when using PhantomJS', + () => { if (window.navigator.userAgent.match(/Chrome|PhantomJS/i)) { return } @@ -81,8 +116,11 @@ describeWithShallowAndMount('scopedSlots', (mountingMethod) => { } }) } - const message = '[vue-test-utils]: the scopedSlots option does not support PhantomJS. Please use Puppeteer, or pass a component.' - expect(fn).to.throw().with.property('message', message) + const message = + '[vue-test-utils]: the scopedSlots option does not support PhantomJS. Please use Puppeteer, or pass a component.' + expect(fn) + .to.throw() + .with.property('message', message) } ) }) diff --git a/test/specs/mounting-options/slots.spec.js b/test/specs/mounting-options/slots.spec.js index 442d1147f..8d56654a3 100644 --- a/test/specs/mounting-options/slots.spec.js +++ b/test/specs/mounting-options/slots.spec.js @@ -2,18 +2,14 @@ import { compileToFunctions } from 'vue-template-compiler' import Component from '~resources/components/component.vue' import ComponentWithSlots from '~resources/components/component-with-slots.vue' import ComponentAsAClass from '~resources/components/component-as-a-class.vue' -import { - describeWithMountingMethods, - vueVersion -} from '~resources/utils' -import { - itSkipIf, - itDoNotRunIf -} from 'conditional-specs' +import { describeWithMountingMethods, vueVersion } from '~resources/utils' +import { itSkipIf, itDoNotRunIf } from 'conditional-specs' -describeWithMountingMethods('options.slots', (mountingMethod) => { +describeWithMountingMethods('options.slots', mountingMethod => { it('mounts component with default slot if passed component in slot object', () => { - const wrapper = mountingMethod(ComponentWithSlots, { slots: { default: Component }}) + const wrapper = mountingMethod(ComponentWithSlots, { + slots: { default: Component } + }) if (mountingMethod.name === 'renderToString') { expect(wrapper).contains('
') } else { @@ -22,9 +18,9 @@ describeWithMountingMethods('options.slots', (mountingMethod) => { }) itDoNotRunIf( - mountingMethod.name === 'shallowMount' || - process.env.TEST_ENV === 'node', - 'mounts component with default slot if passed component as string in slot object', () => { + mountingMethod.name === 'shallowMount' || process.env.TEST_ENV === 'node', + 'mounts component with default slot if passed component as string in slot object', + () => { const CustomComponent = { render: h => h('time') } @@ -47,10 +43,13 @@ describeWithMountingMethods('options.slots', (mountingMethod) => { } else { expect(wrapper.contains('time')).to.equal(true) } - }) + } + ) it('mounts component with default slot if passed component in array in slot object', () => { - const wrapper = mountingMethod(ComponentWithSlots, { slots: { default: [Component] }}) + const wrapper = mountingMethod(ComponentWithSlots, { + slots: { default: [Component] } + }) if (mountingMethod.name === 'renderToString') { expect(wrapper).contains('
') } else { @@ -60,7 +59,9 @@ describeWithMountingMethods('options.slots', (mountingMethod) => { it('mounts component with default slot if passed object with template prop in slot object', () => { const compiled = compileToFunctions('
') - const wrapper = mountingMethod(ComponentWithSlots, { slots: { default: [compiled] }}) + const wrapper = mountingMethod(ComponentWithSlots, { + slots: { default: [compiled] } + }) if (mountingMethod.name === 'renderToString') { expect(wrapper).contains('div id="div"') } else { @@ -70,85 +71,139 @@ describeWithMountingMethods('options.slots', (mountingMethod) => { itDoNotRunIf( process.env.TEST_ENV === 'node', - 'mounts component with default slot if passed string in slot object', () => { - const wrapper = mountingMethod(ComponentWithSlots, { slots: { default: '' }}) + 'mounts component with default slot if passed string in slot object', + () => { + const wrapper = mountingMethod(ComponentWithSlots, { + slots: { default: '' } + }) if (mountingMethod.name === 'renderToString') { expect(wrapper).contains(' { - const wrapper = mountingMethod(ComponentAsAClass, { slots: { default: '' }}) + 'works correctly with class component', + () => { + const wrapper = mountingMethod(ComponentAsAClass, { + slots: { default: '' } + }) if (mountingMethod.name === 'renderToString') { expect(wrapper).contains(' { + 'works if the UserAgent is PhantomJS when passed Component is in slot object', + () => { const windowSave = window global.window = { navigator: { userAgent: 'PhantomJS' }} // eslint-disable-line no-native-reassign - const wrapper = mountingMethod(ComponentWithSlots, { slots: { default: [Component] }}) + const wrapper = mountingMethod(ComponentWithSlots, { + slots: { default: [Component] } + }) if (mountingMethod.name === 'renderToString') { expect(wrapper).contains('
') } else { expect(wrapper.contains(Component)).to.equal(true) } window = windowSave // eslint-disable-line no-native-reassign - }) + } + ) - itSkipIf(mountingMethod.name === 'renderToString', - 'throws error if passed string in default slot object and vue-template-compiler is undefined', () => { - const compilerSave = require.cache[require.resolve('vue-template-compiler')].exports.compileToFunctions - require.cache[require.resolve('vue-template-compiler')].exports.compileToFunctions = undefined + itSkipIf( + mountingMethod.name === 'renderToString', + 'throws error if passed string in default slot object and vue-template-compiler is undefined', + () => { + const compilerSave = + require.cache[require.resolve('vue-template-compiler')].exports + .compileToFunctions + require.cache[ + require.resolve('vue-template-compiler') + ].exports.compileToFunctions = undefined delete require.cache[require.resolve('../../../packages/test-utils')] - const mountingMethodFresh = require('../../../packages/test-utils')[mountingMethod.name] - const message = '[vue-test-utils]: vueTemplateCompiler is undefined, you must pass precompiled components if vue-template-compiler is undefined' - const fn = () => mountingMethodFresh(ComponentWithSlots, { slots: { default: '' }}) + const mountingMethodFresh = require('../../../packages/test-utils')[ + mountingMethod.name + ] + const message = + '[vue-test-utils]: vueTemplateCompiler is undefined, you must pass precompiled components if vue-template-compiler is undefined' + const fn = () => + mountingMethodFresh(ComponentWithSlots, { + slots: { default: '' } + }) try { - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) } catch (err) { - require.cache[require.resolve('vue-template-compiler')].exports.compileToFunctions = compilerSave + require.cache[ + require.resolve('vue-template-compiler') + ].exports.compileToFunctions = compilerSave throw err } - require.cache[require.resolve('vue-template-compiler')].exports.compileToFunctions = compilerSave - }) + require.cache[ + require.resolve('vue-template-compiler') + ].exports.compileToFunctions = compilerSave + } + ) itDoNotRunIf( process.env.TEST_ENV === 'node', - 'mounts component with default slot if passed string in slot array object', () => { - const wrapper = mountingMethod(ComponentWithSlots, { slots: { default: [''] }}) + 'mounts component with default slot if passed string in slot array object', + () => { + const wrapper = mountingMethod(ComponentWithSlots, { + slots: { default: [''] } + }) if (mountingMethod.name === 'renderToString') { expect(wrapper).contains(' { - const compilerSave = require.cache[require.resolve('vue-template-compiler')].exports.compileToFunctions - require.cache[require.resolve('vue-template-compiler')].exports.compileToFunctions = undefined + itSkipIf( + mountingMethod.name === 'renderToString', + 'throws error if passed string in default slot array vue-template-compiler is undefined', + () => { + const compilerSave = + require.cache[require.resolve('vue-template-compiler')].exports + .compileToFunctions + require.cache[ + require.resolve('vue-template-compiler') + ].exports.compileToFunctions = undefined delete require.cache[require.resolve('../../../packages/test-utils')] - const mountingMethodFresh = require('../../../packages/test-utils')[mountingMethod.name] - const message = '[vue-test-utils]: vueTemplateCompiler is undefined, you must pass precompiled components if vue-template-compiler is undefined' - const fn = () => mountingMethodFresh(ComponentWithSlots, { slots: { default: [''] }}) + const mountingMethodFresh = require('../../../packages/test-utils')[ + mountingMethod.name + ] + const message = + '[vue-test-utils]: vueTemplateCompiler is undefined, you must pass precompiled components if vue-template-compiler is undefined' + const fn = () => + mountingMethodFresh(ComponentWithSlots, { + slots: { default: [''] } + }) try { - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) } catch (err) { - require.cache[require.resolve('vue-template-compiler')].exports.compileToFunctions = compilerSave + require.cache[ + require.resolve('vue-template-compiler') + ].exports.compileToFunctions = compilerSave throw err } - require.cache[require.resolve('vue-template-compiler')].exports.compileToFunctions = compilerSave - }) + require.cache[ + require.resolve('vue-template-compiler') + ].exports.compileToFunctions = compilerSave + } + ) it('mounts component with named slot if passed component in slot object', () => { const wrapper = mountingMethod(ComponentWithSlots, { @@ -158,7 +213,9 @@ describeWithMountingMethods('options.slots', (mountingMethod) => { } }) if (mountingMethod.name === 'renderToString') { - expect(wrapper).contains('
') + expect(wrapper).contains( + '
' + ) } else { expect(wrapper.findAll(Component).length).to.equal(2) } @@ -198,10 +255,15 @@ describeWithMountingMethods('options.slots', (mountingMethod) => { functional: true, render: (h, ctx) => h('div', ctx.data, ctx.slots().default) } - const wrapper = mountingMethod(TestComponent, { slots: { default: Component }}) + const wrapper = mountingMethod(TestComponent, { + slots: { default: Component } + }) if (mountingMethod.name === 'renderToString') { - const renderedAttribute = vueVersion < 2.3 ? 'server-rendered' : 'data-server-rendered' - expect(wrapper).contains(`
`) + const renderedAttribute = + vueVersion < 2.3 ? 'server-rendered' : 'data-server-rendered' + expect(wrapper).contains( + `
` + ) } else { expect(wrapper.contains(Component)).to.equal(true) } @@ -213,10 +275,15 @@ describeWithMountingMethods('options.slots', (mountingMethod) => { functional: true, render: (h, ctx) => h('div', ctx.data, ctx.slots().default) } - const wrapper = mountingMethod(TestComponent, { slots: { default: [Component] }}) + const wrapper = mountingMethod(TestComponent, { + slots: { default: [Component] } + }) if (mountingMethod.name === 'renderToString') { - const renderedAttribute = vueVersion < 2.3 ? 'server-rendered' : 'data-server-rendered' - expect(wrapper).contains(`
`) + const renderedAttribute = + vueVersion < 2.3 ? 'server-rendered' : 'data-server-rendered' + expect(wrapper).contains( + `
` + ) } else { expect(wrapper.contains(Component)).to.equal(true) } @@ -229,7 +296,9 @@ describeWithMountingMethods('options.slots', (mountingMethod) => { render: (h, ctx) => h('div', ctx.data, ctx.slots().default) } const compiled = compileToFunctions('
') - const wrapper = mountingMethod(TestComponent, { slots: { default: [compiled] }}) + const wrapper = mountingMethod(TestComponent, { + slots: { default: [compiled] } + }) if (mountingMethod.name === 'renderToString') { expect(wrapper).contains('
') } else { @@ -237,80 +306,101 @@ describeWithMountingMethods('options.slots', (mountingMethod) => { } }) - itDoNotRunIf(process.env.TEST_ENV === 'node', - 'mounts component with default slot if passed string in slot object', () => { + itDoNotRunIf( + process.env.TEST_ENV === 'node', + 'mounts component with default slot if passed string in slot object', + () => { const TestComponent = { name: 'component-with-slots', functional: true, render: (h, ctx) => h('div', ctx.data, ctx.slots().default) } - const wrapper = mountingMethod(TestComponent, { slots: { default: '' }}) + const wrapper = mountingMethod(TestComponent, { + slots: { default: '' } + }) if (mountingMethod.name === 'renderToString') { expect(wrapper).contains(' { + 'mounts component with named slot if passed string in slot object', + () => { const TestComponent = { functional: true, render: (h, ctx) => h('div', {}, ctx.slots().named) } - const wrapper = mountingMethod(TestComponent, { slots: { named: Component }}) + const wrapper = mountingMethod(TestComponent, { + slots: { named: Component } + }) if (mountingMethod.name === 'renderToString') { expect(wrapper).contains('
') } else { expect(wrapper.contains(Component)).to.equal(true) } - }) + } + ) itDoNotRunIf( process.env.TEST_ENV === 'node', - 'mounts component with named slot if passed string in slot object in array', () => { + 'mounts component with named slot if passed string in slot object in array', + () => { const TestComponent = { functional: true, render: (h, ctx) => h('div', {}, ctx.slots().named) } - const wrapper = mountingMethod(TestComponent, { slots: { named: [Component] }}) + const wrapper = mountingMethod(TestComponent, { + slots: { named: [Component] } + }) if (mountingMethod.name === 'renderToString') { expect(wrapper).contains('
') } else { expect(wrapper.contains(Component)).to.equal(true) } - }) + } + ) itDoNotRunIf( process.env.TEST_ENV === 'node', - 'mounts component with named slot if passed string in slot object in array', () => { + 'mounts component with named slot if passed string in slot object in array', + () => { const TestComponent = { functional: true, render: (h, ctx) => h('div', {}, ctx.slots().named) } - const wrapper = mountingMethod(TestComponent, { slots: { named: '' }}) + const wrapper = mountingMethod(TestComponent, { + slots: { named: '' } + }) if (mountingMethod.name === 'renderToString') { expect(wrapper).contains(' { + 'mounts component with named slot if passed string in slot object in array', + () => { const TestComponent = { functional: true, render: (h, ctx) => h('div', {}, ctx.slots().named) } - const wrapper = mountingMethod(TestComponent, { slots: { named: [''] }}) + const wrapper = mountingMethod(TestComponent, { + slots: { named: [''] } + }) if (mountingMethod.name === 'renderToString') { expect(wrapper).contains(' { const TestComponent = { @@ -318,9 +408,13 @@ describeWithMountingMethods('options.slots', (mountingMethod) => { functional: true, render: (h, ctx) => h('div', ctx.data, ctx.slots().default) } - const fn = () => mountingMethod(TestComponent, { slots: { named: [false] }}) - const message = '[vue-test-utils]: slots[key] must be a Component, string or an array of Components' - expect(fn).to.throw().with.property('message', message) + const fn = () => + mountingMethod(TestComponent, { slots: { named: [false] }}) + const message = + '[vue-test-utils]: slots[key] must be a Component, string or an array of Components' + expect(fn) + .to.throw() + .with.property('message', message) }) it('throws error if passed a number for named slots', () => { @@ -330,8 +424,11 @@ describeWithMountingMethods('options.slots', (mountingMethod) => { render: (h, ctx) => h('div', ctx.data, ctx.slots().default) } const fn = () => mountingMethod(TestComponent, { slots: { named: [1] }}) - const message = '[vue-test-utils]: slots[key] must be a Component, string or an array of Components' - expect(fn).to.throw().with.property('message', message) + const message = + '[vue-test-utils]: slots[key] must be a Component, string or an array of Components' + expect(fn) + .to.throw() + .with.property('message', message) }) it('throws error if passed false for named slots', () => { @@ -341,8 +438,11 @@ describeWithMountingMethods('options.slots', (mountingMethod) => { render: (h, ctx) => h('div', ctx.data, ctx.slots().default) } const fn = () => mountingMethod(TestComponent, { slots: { named: false }}) - const message = '[vue-test-utils]: slots[key] must be a Component, string or an array of Components' - expect(fn).to.throw().with.property('message', message) + const message = + '[vue-test-utils]: slots[key] must be a Component, string or an array of Components' + expect(fn) + .to.throw() + .with.property('message', message) }) it('throws error if passed a number for named slots', () => { @@ -352,32 +452,54 @@ describeWithMountingMethods('options.slots', (mountingMethod) => { render: (h, ctx) => h('div', ctx.data, ctx.slots().default) } const fn = () => mountingMethod(TestComponent, { slots: { named: 1 }}) - const message = '[vue-test-utils]: slots[key] must be a Component, string or an array of Components' - expect(fn).to.throw().with.property('message', message) + const message = + '[vue-test-utils]: slots[key] must be a Component, string or an array of Components' + expect(fn) + .to.throw() + .with.property('message', message) }) - itSkipIf(mountingMethod.name === 'renderToString', - 'throws error if passed string in default slot array when vue-template-compiler is undefined', () => { - const compilerSave = require.cache[require.resolve('vue-template-compiler')].exports.compileToFunctions - require.cache[require.resolve('vue-template-compiler')].exports = { compileToFunctions: undefined } + itSkipIf( + mountingMethod.name === 'renderToString', + 'throws error if passed string in default slot array when vue-template-compiler is undefined', + () => { + const compilerSave = + require.cache[require.resolve('vue-template-compiler')].exports + .compileToFunctions + require.cache[require.resolve('vue-template-compiler')].exports = { + compileToFunctions: undefined + } delete require.cache[require.resolve('../../../packages/test-utils')] - const mountingMethodFresh = require('../../../packages/test-utils')[mountingMethod.name] - const message = '[vue-test-utils]: vueTemplateCompiler is undefined, you must pass precompiled components if vue-template-compiler is undefined' + const mountingMethodFresh = require('../../../packages/test-utils')[ + mountingMethod.name + ] + const message = + '[vue-test-utils]: vueTemplateCompiler is undefined, you must pass precompiled components if vue-template-compiler is undefined' const fn = () => { - mountingMethodFresh(ComponentWithSlots, { slots: { default: [''] }}) + mountingMethodFresh(ComponentWithSlots, { + slots: { default: [''] } + }) } try { - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) } catch (err) { - require.cache[require.resolve('vue-template-compiler')].exports.compileToFunctions = compilerSave + require.cache[ + require.resolve('vue-template-compiler') + ].exports.compileToFunctions = compilerSave throw err } - require.cache[require.resolve('vue-template-compiler')].exports.compileToFunctions = compilerSave - }) + require.cache[ + require.resolve('vue-template-compiler') + ].exports.compileToFunctions = compilerSave + } + ) itDoNotRunIf( mountingMethod.name === 'renderToString', - 'does not error when triggering a click in a slot', () => { + 'does not error when triggering a click in a slot', + () => { const Parent = { name: 'Parent', template: ` @@ -403,5 +525,6 @@ describeWithMountingMethods('options.slots', (mountingMethod) => { stubs: { Child } }) wrapper.find('div').trigger('click') - }) + } + ) }) diff --git a/test/specs/mounting-options/stubs.spec.js b/test/specs/mounting-options/stubs.spec.js index a81b48baf..fe89333f1 100644 --- a/test/specs/mounting-options/stubs.spec.js +++ b/test/specs/mounting-options/stubs.spec.js @@ -8,7 +8,7 @@ import Vue from 'vue' import { describeWithMountingMethods } from '~resources/utils' import { itDoNotRunIf } from 'conditional-specs' -describeWithMountingMethods('options.stub', (mountingMethod) => { +describeWithMountingMethods('options.stub', mountingMethod => { let info let warn let configStubsSave @@ -58,8 +58,10 @@ describeWithMountingMethods('options.stub', (mountingMethod) => { } }) - itDoNotRunIf(mountingMethod.name === 'renderToString', - 'replaces component with a component', () => { + itDoNotRunIf( + mountingMethod.name === 'renderToString', + 'replaces component with a component', + () => { const wrapper = mountingMethod(ComponentWithChild, { stubs: { ChildComponent: { @@ -72,7 +74,8 @@ describeWithMountingMethods('options.stub', (mountingMethod) => { }) expect(wrapper.findAll(Component).length).to.equal(1) expect(info.calledWith('stubbed')).to.equal(true) - }) + } + ) it('does not error if component to stub contains no components', () => { mountingMethod(Component, { @@ -82,19 +85,22 @@ describeWithMountingMethods('options.stub', (mountingMethod) => { }) }) - itDoNotRunIf(mountingMethod.name === 'shallowMount' || - mountingMethod.name === 'renderToString', - 'does not modify component directly', () => { - const wrapper = mountingMethod(ComponentWithNestedChildren, { - stubs: { - ChildComponent: '
' - } - }) - expect(wrapper.findAll(Component).length).to.equal(0) + itDoNotRunIf( + mountingMethod.name === 'shallowMount' || + mountingMethod.name === 'renderToString', + 'does not modify component directly', + () => { + const wrapper = mountingMethod(ComponentWithNestedChildren, { + stubs: { + ChildComponent: '
' + } + }) + expect(wrapper.findAll(Component).length).to.equal(0) - const mountedWrapper = mountingMethod(ComponentWithNestedChildren) - expect(mountedWrapper.findAll(Component).length).to.equal(1) - }) + const mountedWrapper = mountingMethod(ComponentWithNestedChildren) + expect(mountedWrapper.findAll(Component).length).to.equal(1) + } + ) it('stubs components on component if they do not already exist', () => { const ComponentWithGlobalComponent = { @@ -105,9 +111,8 @@ describeWithMountingMethods('options.stub', (mountingMethod) => { 'registered-component': Component } }) - const HTML = mountingMethod.name === 'renderToString' - ? wrapper - : wrapper.html() + const HTML = + mountingMethod.name === 'renderToString' ? wrapper : wrapper.html() expect(HTML).to.contain('
') }) @@ -118,9 +123,8 @@ describeWithMountingMethods('options.stub', (mountingMethod) => { const wrapper = mountingMethod(ComponentWithGlobalComponent, { stubs: ['registered-component'] }) - const HTML = mountingMethod.name === 'renderToString' - ? wrapper - : wrapper.html() + const HTML = + mountingMethod.name === 'renderToString' ? wrapper : wrapper.html() expect(HTML).to.contain('') }) @@ -133,9 +137,8 @@ describeWithMountingMethods('options.stub', (mountingMethod) => { 'registered-component': true } }) - const HTML = mountingMethod.name === 'renderToString' - ? wrapper - : wrapper.html() + const HTML = + mountingMethod.name === 'renderToString' ? wrapper : wrapper.html() expect(HTML).to.contain('') }) @@ -144,49 +147,71 @@ describeWithMountingMethods('options.stub', (mountingMethod) => { render: h => h('registered-component') } const invalidValues = [{}, [], 3] - const error = '[vue-test-utils]: each item in an options.stubs array must be a string' + const error = + '[vue-test-utils]: each item in an options.stubs array must be a string' invalidValues.forEach(invalidValue => { - const fn = () => mountingMethod(ComponentWithGlobalComponent, { - stubs: [invalidValue] - }) - expect(fn).to.throw().with.property('message', error) + const fn = () => + mountingMethod(ComponentWithGlobalComponent, { + stubs: [invalidValue] + }) + expect(fn) + .to.throw() + .with.property('message', error) }) }) it('throws error if passed string in object when vue-template-compiler is undefined', () => { - const compilerSave = require.cache[require.resolve('vue-template-compiler')].exports.compileToFunctions - require.cache[require.resolve('vue-template-compiler')].exports.compileToFunctions = undefined + const compilerSave = + require.cache[require.resolve('vue-template-compiler')].exports + .compileToFunctions + require.cache[ + require.resolve('vue-template-compiler') + ].exports.compileToFunctions = undefined delete require.cache[require.resolve('../../../packages/test-utils')] - delete require.cache[require.resolve('../../../packages/server-test-utils')] - const mountingMethodFresh = mountingMethod.name === 'renderToString' - ? require('../../../packages/server-test-utils').renderToString - : require('../../../packages/test-utils')[mountingMethod.name] - const message = '[vue-test-utils]: vueTemplateCompiler is undefined, you must pass precompiled components if vue-template-compiler is undefined' - const fn = () => mountingMethodFresh(Component, { - stubs: { - ChildComponent: '
' - } - }) + delete require.cache[ + require.resolve('../../../packages/server-test-utils') + ] + const mountingMethodFresh = + mountingMethod.name === 'renderToString' + ? require('../../../packages/server-test-utils').renderToString + : require('../../../packages/test-utils')[mountingMethod.name] + const message = + '[vue-test-utils]: vueTemplateCompiler is undefined, you must pass precompiled components if vue-template-compiler is undefined' + const fn = () => + mountingMethodFresh(Component, { + stubs: { + ChildComponent: '
' + } + }) try { - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) } catch (err) { - require.cache[require.resolve('vue-template-compiler')].exports.compileToFunctions = compilerSave + require.cache[ + require.resolve('vue-template-compiler') + ].exports.compileToFunctions = compilerSave throw err } - require.cache[require.resolve('vue-template-compiler')].exports.compileToFunctions = compilerSave + require.cache[ + require.resolve('vue-template-compiler') + ].exports.compileToFunctions = compilerSave }) - itDoNotRunIf(mountingMethod.name === 'shallowMount', - 'does not stub component when set to false', () => { + itDoNotRunIf( + mountingMethod.name === 'shallowMount', + 'does not stub component when set to false', + () => { const wrapper = mountingMethod(ComponentWithChild, { stubs: { ChildComponent: false - }}) - const HTML = mountingMethod.name === 'renderToString' - ? wrapper - : wrapper.html() + } + }) + const HTML = + mountingMethod.name === 'renderToString' ? wrapper : wrapper.html() expect(HTML).to.contain('
') - }) + } + ) it('combines with stubs from config', () => { const localVue = createLocalVue() @@ -202,10 +227,7 @@ describeWithMountingMethods('options.stub', (mountingMethod) => { localVue.component('span-component', SpanComponent) localVue.component('time-component', TimeComponent) const TestComponent = { - render: h => h('div', [ - h('span-component'), - h('time-component') - ]) + render: h => h('div', [h('span-component'), h('time-component')]) } const wrapper = mountingMethod(TestComponent, { @@ -214,9 +236,8 @@ describeWithMountingMethods('options.stub', (mountingMethod) => { }, localVue }) - const HTML = mountingMethod.name === 'renderToString' - ? wrapper - : wrapper.html() + const HTML = + mountingMethod.name === 'renderToString' ? wrapper : wrapper.html() expect(HTML).to.contain('
') expect(HTML).to.contain('

') }) @@ -229,9 +250,7 @@ describeWithMountingMethods('options.stub', (mountingMethod) => { } localVue.component('time-component', TimeComponent) const TestComponent = { - render: h => h('div', [ - h('time-component') - ]) + render: h => h('div', [h('time-component')]) } const wrapper = mountingMethod(TestComponent, { @@ -240,28 +259,32 @@ describeWithMountingMethods('options.stub', (mountingMethod) => { }, localVue }) - const HTML = mountingMethod.name === 'renderToString' - ? wrapper - : wrapper.html() + const HTML = + mountingMethod.name === 'renderToString' ? wrapper : wrapper.html() expect(HTML).to.contain('') }) itDoNotRunIf( mountingMethod.name === 'shallowMount' || - mountingMethod.name === 'renderToString', - 'stubs on child components', () => { + mountingMethod.name === 'renderToString', + 'stubs on child components', + () => { const TestComponent = { template: '' } - const wrapper = mountingMethod({ - components: { 'test-component': TestComponent }, - template: '' - }, { - stubs: ['transition'] - }) + const wrapper = mountingMethod( + { + components: { 'test-component': TestComponent }, + template: '' + }, + { + stubs: ['transition'] + } + ) expect(wrapper.find('span').exists()).to.equal(false) - }) + } + ) it('converts config to array if stubs is an array', () => { const localVue = createLocalVue() @@ -272,9 +295,7 @@ describeWithMountingMethods('options.stub', (mountingMethod) => { } localVue.component('time-component', TimeComponent) const TestComponent = { - render: h => h('div', [ - h('time-component') - ]) + render: h => h('div', [h('time-component')]) } const wrapper = mountingMethod(TestComponent, { @@ -282,9 +303,8 @@ describeWithMountingMethods('options.stub', (mountingMethod) => { localVue }) - const HTML = mountingMethod.name === 'renderToString' - ? wrapper - : wrapper.html() + const HTML = + mountingMethod.name === 'renderToString' ? wrapper : wrapper.html() expect(HTML).to.contain('') }) @@ -308,9 +328,8 @@ describeWithMountingMethods('options.stub', (mountingMethod) => { 'stub-component': StubComponent } }) - const HTML = mountingMethod.name === 'renderToString' - ? wrapper - : wrapper.html() + const HTML = + mountingMethod.name === 'renderToString' ? wrapper : wrapper.html() expect(HTML).contains('No render function') }) @@ -330,33 +349,44 @@ describeWithMountingMethods('options.stub', (mountingMethod) => { '', '' ] - const error = '[vue-test-utils]: options.stub cannot contain a circular reference' - names.forEach((name) => { + const error = + '[vue-test-utils]: options.stub cannot contain a circular reference' + names.forEach(name => { invalidValues.forEach(invalidValue => { - const fn = () => mountingMethod(ComponentWithChild, { - stubs: { - ChildComponent: invalidValue.replace(/NAME/g, name) - }}) - expect(fn).to.throw().with.property('message', error) + const fn = () => + mountingMethod(ComponentWithChild, { + stubs: { + ChildComponent: invalidValue.replace(/NAME/g, name) + } + }) + expect(fn) + .to.throw() + .with.property('message', error) }) - validValues.forEach((validValue) => { + validValues.forEach(validValue => { mountingMethod(ComponentWithChild, { stubs: { ChildComponent: validValue.replace(/NAME/g, name) - }}) + } + }) }) }) }) it('throws an error when passed an invalid value as stub', () => { - const error = '[vue-test-utils]: options.stub values must be passed a string or component' + const error = + '[vue-test-utils]: options.stub values must be passed a string or component' const invalidValues = [1, null, [], {}, NaN] invalidValues.forEach(invalidValue => { - const fn = () => mountingMethod(ComponentWithChild, { - stubs: { - ChildComponent: invalidValue - }}) - expect(fn).to.throw().with.property('message', error) + const fn = () => + mountingMethod(ComponentWithChild, { + stubs: { + ChildComponent: invalidValue + } + }) + expect(fn) + .to.throw() + .with.property('message', error) }) }) }) diff --git a/test/specs/mounting-options/sync.spec.js b/test/specs/mounting-options/sync.spec.js index 2268c4e0b..fab7cc3d7 100644 --- a/test/specs/mounting-options/sync.spec.js +++ b/test/specs/mounting-options/sync.spec.js @@ -1,7 +1,7 @@ import sinon from 'sinon' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('options.sync', (mountingMethod) => { +describeWithShallowAndMount('options.sync', mountingMethod => { it('sets watchers to sync if set to true', () => { const TestComponent = { template: '

{{someData}}
', @@ -91,7 +91,7 @@ describeWithShallowAndMount('options.sync', (mountingMethod) => { expect(wrapper.vm.basket[0]).to.equal('foo') }) - it('does not set watchers to sync if set to false', (done) => { + it('does not set watchers to sync if set to false', done => { const TestComponent = { template: '
{{someData}}
', data: () => ({ diff --git a/test/specs/renderToString.spec.js b/test/specs/renderToString.spec.js index 60e398933..156df6132 100644 --- a/test/specs/renderToString.spec.js +++ b/test/specs/renderToString.spec.js @@ -4,10 +4,12 @@ import { isRunningJSDOM } from '~resources/utils' import { itDoNotRunIf } from 'conditional-specs' describe.skip('renderToString', () => { - itDoNotRunIf(isRunningJSDOM, - 'throws error when not run in node', () => { - const fn = () => renderToString(Component) - const message = '[vue-test-utils]: renderToString must be run in node. It cannot be run in a browser' - expect(fn).to.throw().with.property('message', message) - }) + itDoNotRunIf(isRunningJSDOM, 'throws error when not run in node', () => { + const fn = () => renderToString(Component) + const message = + '[vue-test-utils]: renderToString must be run in node. It cannot be run in a browser' + expect(fn) + .to.throw() + .with.property('message', message) + }) }) diff --git a/test/specs/shallow-mount.spec.js b/test/specs/shallow-mount.spec.js index d6baa1c82..41f75b41b 100644 --- a/test/specs/shallow-mount.spec.js +++ b/test/specs/shallow-mount.spec.js @@ -11,238 +11,243 @@ import RecursiveComponent from '~resources/components/recursive-component.vue' import { vueVersion } from '~resources/utils' import { describeRunIf, itDoNotRunIf } from 'conditional-specs' -describeRunIf(process.env.TEST_ENV !== 'node', - 'shallowMount', () => { - beforeEach(() => { - sinon.stub(console, 'info') - sinon.stub(console, 'error') - }) - - afterEach(() => { - console.info.restore() - console.error.restore() - }) - - it('returns new VueWrapper of Vue localVue if no options are passed', () => { - const compiled = compileToFunctions('
') - const wrapper = shallowMount(compiled) - expect(wrapper.isVueInstance()).to.equal(true) - expect(wrapper.vm).to.be.an('object') - }) - - it('returns new VueWrapper of Vue localVue with all children stubbed', () => { - const wrapper = shallowMount(ComponentWithNestedChildren) - expect(wrapper.isVueInstance()).to.equal(true) - expect(wrapper.findAll(Component).length).to.equal(0) - expect(wrapper.findAll(ComponentWithChild).length).to.equal(1) - }) - - it('returns new VueWrapper of Vue localVue with all children stubbed', () => { - const wrapper = shallowMount(ComponentWithNestedChildren) - expect(wrapper.isVueInstance()).to.equal(true) - expect(wrapper.findAll(Component).length).to.equal(0) - expect(wrapper.findAll(ComponentWithChild).length).to.equal(1) - }) - - it('does not modify component directly', () => { - const wrapper = shallowMount(ComponentWithNestedChildren) - expect(wrapper.findAll(Component).length).to.equal(0) - const mountedWrapper = mount(ComponentWithNestedChildren) - expect(mountedWrapper.findAll(Component).length).to.equal(1) - }) - - it('stubs globally registered components when options.localVue is provided', () => { - const localVue = Vue.extend() - localVue.component('registered-component', ComponentWithLifecycleHooks) - const TestComponent = { - render: h => h('registered-component') - } - shallowMount(TestComponent, { localVue }) - localVue.component('registered-component', ComponentWithLifecycleHooks) - mount(TestComponent, { localVue }) +describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { + beforeEach(() => { + sinon.stub(console, 'info') + sinon.stub(console, 'error') + }) - expect(console.info.callCount).to.equal(4) - }) + afterEach(() => { + console.info.restore() + console.error.restore() + }) - it('stubs globally registered components', () => { - Vue.component('registered-component', ComponentWithLifecycleHooks) - const Component = { - render: h => h('registered-component') - } - shallowMount(Component) - mount(Component) + it('returns new VueWrapper of Vue localVue if no options are passed', () => { + const compiled = compileToFunctions('
') + const wrapper = shallowMount(compiled) + expect(wrapper.isVueInstance()).to.equal(true) + expect(wrapper.vm).to.be.an('object') + }) - expect(console.info.callCount).to.equal(4) - }) + it('returns new VueWrapper of Vue localVue with all children stubbed', () => { + const wrapper = shallowMount(ComponentWithNestedChildren) + expect(wrapper.isVueInstance()).to.equal(true) + expect(wrapper.findAll(Component).length).to.equal(0) + expect(wrapper.findAll(ComponentWithChild).length).to.equal(1) + }) - itDoNotRunIf( - vueVersion < 2.1, - 'adds stubbed components to ignored elements', () => { - const TestComponent = { - template: ` + it('returns new VueWrapper of Vue localVue with all children stubbed', () => { + const wrapper = shallowMount(ComponentWithNestedChildren) + expect(wrapper.isVueInstance()).to.equal(true) + expect(wrapper.findAll(Component).length).to.equal(0) + expect(wrapper.findAll(ComponentWithChild).length).to.equal(1) + }) + + it('does not modify component directly', () => { + const wrapper = shallowMount(ComponentWithNestedChildren) + expect(wrapper.findAll(Component).length).to.equal(0) + const mountedWrapper = mount(ComponentWithNestedChildren) + expect(mountedWrapper.findAll(Component).length).to.equal(1) + }) + + it('stubs globally registered components when options.localVue is provided', () => { + const localVue = Vue.extend() + localVue.component('registered-component', ComponentWithLifecycleHooks) + const TestComponent = { + render: h => h('registered-component') + } + shallowMount(TestComponent, { localVue }) + localVue.component('registered-component', ComponentWithLifecycleHooks) + mount(TestComponent, { localVue }) + + expect(console.info.callCount).to.equal(4) + }) + + it('stubs globally registered components', () => { + Vue.component('registered-component', ComponentWithLifecycleHooks) + const Component = { + render: h => h('registered-component') + } + shallowMount(Component) + mount(Component) + + expect(console.info.callCount).to.equal(4) + }) + + itDoNotRunIf( + vueVersion < 2.1, + 'adds stubbed components to ignored elements', + () => { + const TestComponent = { + template: `
`, - components: { - 'router-link': { - template: '
' - }, - 'custom-component': { - template: '
' - } + components: { + 'router-link': { + template: '
' + }, + 'custom-component': { + template: '
' } } - shallowMount(TestComponent) - expect(console.error).not.called - }) - - itDoNotRunIf( - vueVersion < 2.1, - 'handles recursive components', () => { - const TestComponent = { - template: ` + } + shallowMount(TestComponent) + expect(console.error).not.called + } + ) + + itDoNotRunIf(vueVersion < 2.1, 'handles recursive components', () => { + const TestComponent = { + template: `
`, - name: 'test-component' - } - const wrapper = shallowMount(TestComponent) - expect(wrapper.html()).to.contain('') - expect(console.error).not.called - }) + name: 'test-component' + } + const wrapper = shallowMount(TestComponent) + expect(wrapper.html()).to.contain('') + expect(console.error).not.called + }) - it('does not call stubbed children lifecycle hooks', () => { - shallowMount(ComponentWithNestedChildren) - expect(console.info.called).to.equal(false) - }) + it('does not call stubbed children lifecycle hooks', () => { + shallowMount(ComponentWithNestedChildren) + expect(console.info.called).to.equal(false) + }) - it('stubs extended components', () => { - const ComponentWithPTag = { - template: `

` - } - const BaseComponent = { - template: ` + it('stubs extended components', () => { + const ComponentWithPTag = { + template: `

` + } + const BaseComponent = { + template: `
`, - components: { - ComponentWithPTag - } + components: { + ComponentWithPTag } + } - const TestComponent = { - extends: BaseComponent - } + const TestComponent = { + extends: BaseComponent + } - const wrapper = shallowMount(TestComponent) - expect(wrapper.find(ComponentWithPTag).exists()).to.equal(true) - expect(wrapper.find('p').exists()).to.equal(false) - }) + const wrapper = shallowMount(TestComponent) + expect(wrapper.find(ComponentWithPTag).exists()).to.equal(true) + expect(wrapper.find('p').exists()).to.equal(false) + }) - it('stubs nested extended components', () => { - const ComponentWithPTag = { - template: `

` - } - const BaseComponent = { - template: ` + it('stubs nested extended components', () => { + const ComponentWithPTag = { + template: `

` + } + const BaseComponent = { + template: `
`, - components: { - ComponentWithPTag - } + components: { + ComponentWithPTag } + } - const ExtendedBaseComponent = { - extends: BaseComponent - } + const ExtendedBaseComponent = { + extends: BaseComponent + } - const TestComponent = { - extends: ExtendedBaseComponent - } + const TestComponent = { + extends: ExtendedBaseComponent + } - const wrapper = shallowMount(TestComponent) - expect(wrapper.find(ComponentWithPTag).exists()).to.equal(true) - expect(wrapper.find('p').exists()).to.equal(false) - }) + const wrapper = shallowMount(TestComponent) + expect(wrapper.find(ComponentWithPTag).exists()).to.equal(true) + expect(wrapper.find('p').exists()).to.equal(false) + }) - it('stubs Vue class component children', () => { - if (vueVersion < 2.3) { - return - } - const wrapper = shallowMount(ComponentAsAClassWithChild) - expect(wrapper.find(Component).exists()).to.equal(true) - expect(wrapper.findAll('div').length).to.equal(1) - }) + it('stubs Vue class component children', () => { + if (vueVersion < 2.3) { + return + } + const wrapper = shallowMount(ComponentAsAClassWithChild) + expect(wrapper.find(Component).exists()).to.equal(true) + expect(wrapper.findAll('div').length).to.equal(1) + }) - it('works correctly with find, contains, findAll, and is on unnamed components', () => { - const TestComponent = { - template: ` + it('works correctly with find, contains, findAll, and is on unnamed components', () => { + const TestComponent = { + template: `
`, - components: { - ComponentWithoutName - } + components: { + ComponentWithoutName } - const wrapper = shallowMount(TestComponent) - expect(wrapper.contains(ComponentWithoutName)).to.equal(true) - expect(wrapper.find(ComponentWithoutName).exists()).to.equal(true) - expect(wrapper.findAll(ComponentWithoutName).length).to.equal(1) - }) + } + const wrapper = shallowMount(TestComponent) + expect(wrapper.contains(ComponentWithoutName)).to.equal(true) + expect(wrapper.find(ComponentWithoutName).exists()).to.equal(true) + expect(wrapper.findAll(ComponentWithoutName).length).to.equal(1) + }) - it('works correctly with find, contains, findAll, and is on named components', () => { - const TestComponent = { - template: ` + it('works correctly with find, contains, findAll, and is on named components', () => { + const TestComponent = { + template: `
`, - components: { - AComponent: Component - } + components: { + AComponent: Component } - const wrapper = shallowMount(TestComponent) - expect(wrapper.contains(Component)).to.equal(true) - expect(wrapper.find(Component).exists()).to.equal(true) - expect(wrapper.findAll(Component).length).to.equal(1) - }) + } + const wrapper = shallowMount(TestComponent) + expect(wrapper.contains(Component)).to.equal(true) + expect(wrapper.find(Component).exists()).to.equal(true) + expect(wrapper.findAll(Component).length).to.equal(1) + }) - it('works correctly with find on recursive components', () => { + it('works correctly with find on recursive components', () => { // this is for a bug that I've been unable to replicate. // Sometimes components mutate their components, in this line— - RecursiveComponent.components = { - RecursiveComponent: { render: h => h('div') } - } + RecursiveComponent.components = { + RecursiveComponent: { render: h => h('div') } + } - expect(shallowMount(RecursiveComponent, { + expect( + shallowMount(RecursiveComponent, { propsData: { items: ['', ''] } - }).findAll(RecursiveComponent).length).to.equal(3) - RecursiveComponent.components = { - 'recursive-component': { render: h => h('div') } - } - expect(shallowMount(RecursiveComponent, { + }).findAll(RecursiveComponent).length + ).to.equal(3) + RecursiveComponent.components = { + 'recursive-component': { render: h => h('div') } + } + expect( + shallowMount(RecursiveComponent, { propsData: { items: ['', ''] } - }).findAll(RecursiveComponent).length).to.equal(3) - }) + }).findAll(RecursiveComponent).length + ).to.equal(3) + }) - it('throws an error when the component fails to mount', () => { - expect(() => shallowMount({ + it('throws an error when the component fails to mount', () => { + expect(() => + shallowMount({ template: '
', mounted: function () { - throw (new Error('Error')) + throw new Error('Error') } - })).to.throw() - }) + }) + ).to.throw() }) +}) diff --git a/test/specs/wrapper-array.spec.js b/test/specs/wrapper-array.spec.js index 50d3b6da6..dbd0217e2 100644 --- a/test/specs/wrapper-array.spec.js +++ b/test/specs/wrapper-array.spec.js @@ -1,7 +1,7 @@ import { compileToFunctions } from 'vue-template-compiler' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('WrapperArray', (mountingMethod) => { +describeWithShallowAndMount('WrapperArray', mountingMethod => { function getWrapperArray (wrappers) { const compiled = compileToFunctions('

1

2

3

') const wrapper = mountingMethod(compiled) @@ -26,15 +26,43 @@ describeWithShallowAndMount('WrapperArray', (mountingMethod) => { it('returns filtered wrapper when filter is called', () => { const wrapperArray = getWrapperArray() - expect(wrapperArray.filter(w => { - return w.text() !== '2' - }).length).to.equal(2) + expect( + wrapperArray.filter(w => { + return w.text() !== '2' + }).length + ).to.equal(2) }) - const methods = ['at', 'attributes', 'classes', 'contains', 'emitted', 'emittedByOrder', 'hasAttribute', - 'hasClass', 'hasProp', 'hasStyle', 'find', 'findAll', 'html', 'text', 'is', 'isEmpty', 'isVisible', 'isVueInstance', - 'name', 'props', 'setComputed', 'setMethods', 'setData', 'setProps', 'trigger', 'update', 'destroy'] - methods.forEach((method) => { + const methods = [ + 'at', + 'attributes', + 'classes', + 'contains', + 'emitted', + 'emittedByOrder', + 'hasAttribute', + '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`, () => { if (method === 'at') { return @@ -42,24 +70,47 @@ describeWithShallowAndMount('WrapperArray', (mountingMethod) => { const wrapperArray = getWrapperArray() wrapperArray.wrappers = [] const message = `[vue-test-utils]: ${method} cannot be called on 0 items` - expect(() => wrapperArray[method]()).to.throw().with.property('message', message) + expect(() => wrapperArray[method]()) + .to.throw() + .with.property('message', message) }) it(`${method} throws error if called when there are items in wrapper array`, () => { - if (['at', 'contains', 'hasAttribute', 'hasClass', 'hasProp', 'hasStyle', 'is', 'isEmpty', 'isVisible', 'isVueInstance', - 'setComputed', 'setMethods', 'setData', 'setProps', 'trigger', 'update', 'destroy'].includes(method)) { + if ( + [ + 'at', + 'contains', + 'hasAttribute', + 'hasClass', + 'hasProp', + 'hasStyle', + 'is', + 'isEmpty', + 'isVisible', + 'isVueInstance', + 'setComputed', + 'setMethods', + 'setData', + 'setProps', + 'trigger', + 'update', + 'destroy' + ].includes(method) + ) { return } const wrapperArray = getWrapperArray() wrapperArray.wrappers = [1, 2, 3] const message = `[vue-test-utils]: ${method} must be called on a single wrapper, use at(i) to access a wrapper` - expect(() => wrapperArray[method]()).to.throw().with.property('message', message) + expect(() => wrapperArray[method]()) + .to.throw() + .with.property('message', message) }) }) it('exists returns true if it has every existing wrappers', () => { const wrapperArray = getWrapperArray() - wrapperArray.wrappers.forEach((w) => { + wrapperArray.wrappers.forEach(w => { expect(w.exists()).to.equal(true) }) expect(wrapperArray.exists()).to.equal(true) @@ -94,7 +145,10 @@ describeWithShallowAndMount('WrapperArray', (mountingMethod) => { }) it('contains returns false if not every wrapper.contains() returns true', () => { - const wrapperArray = getWrapperArray([{ contains: () => true }, { contains: () => false }]) + const wrapperArray = getWrapperArray([ + { contains: () => true }, + { contains: () => false } + ]) expect(wrapperArray.contains()).to.equal(false) }) @@ -108,7 +162,10 @@ describeWithShallowAndMount('WrapperArray', (mountingMethod) => { }) it('hasAttribute returns false if not every wrapper.hasAttribute() returns true', () => { - const wrapperArray = getWrapperArray([{ hasAttribute: () => true }, { hasAttribute: () => false }]) + const wrapperArray = getWrapperArray([ + { hasAttribute: () => true }, + { hasAttribute: () => false } + ]) expect(wrapperArray.hasAttribute('attribute', 'value')).to.equal(false) }) @@ -121,7 +178,10 @@ describeWithShallowAndMount('WrapperArray', (mountingMethod) => { }) it('hasClass returns false if not every wrapper.hasClass() returns true', () => { - const wrapperArray = getWrapperArray([{ hasClass: () => true }, { hasClass: () => false }]) + const wrapperArray = getWrapperArray([ + { hasClass: () => true }, + { hasClass: () => false } + ]) expect(wrapperArray.hasClass('class')).to.equal(false) }) @@ -135,7 +195,10 @@ describeWithShallowAndMount('WrapperArray', (mountingMethod) => { }) it('hasProp returns false if not every wrapper.hasProp() returns true', () => { - const wrapperArray = getWrapperArray([{ hasProp: () => true }, { hasProp: () => false }]) + const wrapperArray = getWrapperArray([ + { hasProp: () => true }, + { hasProp: () => false } + ]) expect(wrapperArray.hasProp('prop', 'value')).to.equal(false) }) @@ -149,7 +212,10 @@ describeWithShallowAndMount('WrapperArray', (mountingMethod) => { }) it('hasStyle returns false if not every wrapper.hasStyle() returns true', () => { - const wrapperArray = getWrapperArray([{ hasStyle: () => true }, { hasStyle: () => false }]) + const wrapperArray = getWrapperArray([ + { hasStyle: () => true }, + { hasStyle: () => false } + ]) expect(wrapperArray.hasStyle('style', 'value')).to.equal(false) }) @@ -162,37 +228,58 @@ describeWithShallowAndMount('WrapperArray', (mountingMethod) => { }) it('is returns false if not every wrapper.is() returns true', () => { - const wrapperArray = getWrapperArray([{ is: () => true }, { is: () => false }]) + const wrapperArray = getWrapperArray([ + { is: () => true }, + { is: () => false } + ]) expect(wrapperArray.is('selector')).to.equal(false) }) it('isEmpty returns true if every wrapper.isEmpty() returns true', () => { - const wrapperArray = getWrapperArray([{ isEmpty: () => true }, { isEmpty: () => true }]) + const wrapperArray = getWrapperArray([ + { isEmpty: () => true }, + { isEmpty: () => true } + ]) expect(wrapperArray.isEmpty()).to.equal(true) }) it('isEmpty returns false if not every wrapper.isEmpty() returns true', () => { - const wrapperArray = getWrapperArray([{ isEmpty: () => true }, { isEmpty: () => false }]) + const wrapperArray = getWrapperArray([ + { isEmpty: () => true }, + { isEmpty: () => false } + ]) expect(wrapperArray.isEmpty()).to.equal(false) }) it('isVisible returns true if every wrapper.isVisible() returns true', () => { - const wrapperArray = getWrapperArray([{ isVisible: () => true }, { isVisible: () => 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 }]) + 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 }]) + const wrapperArray = getWrapperArray([ + { isVueInstance: () => true }, + { isVueInstance: () => true } + ]) expect(wrapperArray.isVueInstance()).to.equal(true) }) it('isVueInstance returns false if not every wrapper.isVueInstance() returns true', () => { - const wrapperArray = getWrapperArray([{ isVueInstance: () => true }, { isVueInstance: () => false }]) + const wrapperArray = getWrapperArray([ + { isVueInstance: () => true }, + { isVueInstance: () => false } + ]) expect(wrapperArray.isVueInstance()).to.equal(false) }) diff --git a/test/specs/wrapper-array/at.spec.js b/test/specs/wrapper-array/at.spec.js index e9d3b503c..104f66e4d 100644 --- a/test/specs/wrapper-array/at.spec.js +++ b/test/specs/wrapper-array/at.spec.js @@ -2,10 +2,12 @@ import { describeWithShallowAndMount } from '~resources/utils' import { compileToFunctions } from 'vue-template-compiler' import '~vue/test-utils' -describeWithShallowAndMount('at', (mountingMethod) => { +describeWithShallowAndMount('at', mountingMethod => { it('returns Wrapper at index', () => { const compiled = compileToFunctions('

') - const p = mountingMethod(compiled).findAll('p').at(1) + const p = mountingMethod(compiled) + .findAll('p') + .at(1) expect(p.vnode).to.be.an('object') expect(p.hasClass('index-1')).to.equal(true) }) @@ -14,6 +16,12 @@ describeWithShallowAndMount('at', (mountingMethod) => { const index = 2 const compiled = compileToFunctions('

') const message = `[vue-test-utils]: no item exists at ${index}` - expect(() => mountingMethod(compiled).findAll('p').at(index)).to.throw().with.property('message', message) + expect(() => + mountingMethod(compiled) + .findAll('p') + .at(index) + ) + .to.throw() + .with.property('message', message) }) }) diff --git a/test/specs/wrapper-array/attributes.spec.js b/test/specs/wrapper-array/attributes.spec.js index 435a5c511..69c8daee5 100644 --- a/test/specs/wrapper-array/attributes.spec.js +++ b/test/specs/wrapper-array/attributes.spec.js @@ -2,18 +2,27 @@ import { describeWithShallowAndMount } from '~resources/utils' import { compileToFunctions } from 'vue-template-compiler' import '~vue/test-utils' -describeWithShallowAndMount('attributes', (mountingMethod) => { +describeWithShallowAndMount('attributes', mountingMethod => { it('throws error if wrapper array contains no items', () => { const compiled = compileToFunctions('
') const message = '[vue-test-utils]: attributes cannot be called on 0 items' - expect(() => mountingMethod(compiled).findAll('p').attributes('p')).to.throw().with.property('message', message) + expect(() => + mountingMethod(compiled) + .findAll('p') + .attributes('p') + ) + .to.throw() + .with.property('message', message) }) it('throws error when called on a WrapperArray', () => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) - const message = '[vue-test-utils]: attributes must be called on a single wrapper, use at(i) to access a wrapper' + const message = + '[vue-test-utils]: attributes must be called on a single wrapper, use at(i) to access a wrapper' const fn = () => wrapper.findAll('div').attributes() - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) }) }) diff --git a/test/specs/wrapper-array/classes.spec.js b/test/specs/wrapper-array/classes.spec.js index e92e8a131..5c1d08fd9 100644 --- a/test/specs/wrapper-array/classes.spec.js +++ b/test/specs/wrapper-array/classes.spec.js @@ -2,18 +2,27 @@ import { describeWithShallowAndMount } from '~resources/utils' import { compileToFunctions } from 'vue-template-compiler' import '~vue/test-utils' -describeWithShallowAndMount('classes', (mountingMethod) => { +describeWithShallowAndMount('classes', mountingMethod => { it('throws error if wrapper array contains no items', () => { const compiled = compileToFunctions('
') const message = '[vue-test-utils]: classes cannot be called on 0 items' - expect(() => mountingMethod(compiled).findAll('p').classes('p')).to.throw().with.property('message', message) + expect(() => + mountingMethod(compiled) + .findAll('p') + .classes('p') + ) + .to.throw() + .with.property('message', message) }) it('throws error when called on a WrapperArray', () => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) - const message = '[vue-test-utils]: classes must be called on a single wrapper, use at(i) to access a wrapper' + const message = + '[vue-test-utils]: classes must be called on a single wrapper, use at(i) to access a wrapper' const fn = () => wrapper.findAll('div').classes() - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) }) }) diff --git a/test/specs/wrapper-array/contains.spec.js b/test/specs/wrapper-array/contains.spec.js index 14e1a3d61..975aac550 100644 --- a/test/specs/wrapper-array/contains.spec.js +++ b/test/specs/wrapper-array/contains.spec.js @@ -2,16 +2,20 @@ import { describeWithShallowAndMount } from '~resources/utils' import { compileToFunctions } from 'vue-template-compiler' import '~vue/test-utils' -describeWithShallowAndMount('contains', (mountingMethod) => { +describeWithShallowAndMount('contains', mountingMethod => { it('returns true if every Wrapper contains element', () => { - const compiled = compileToFunctions('

') + const compiled = compileToFunctions( + '

' + ) const wrapper = mountingMethod(compiled) const divArr = wrapper.findAll('div') expect(divArr.contains('p')).to.equal(true) }) it('returns false if any Wrapper does not contain element', () => { - const compiled = compileToFunctions('

') + const compiled = compileToFunctions( + '

' + ) const wrapper = mountingMethod(compiled) const divArr = wrapper.findAll('div') expect(divArr.contains('p')).to.equal(false) @@ -20,7 +24,13 @@ describeWithShallowAndMount('contains', (mountingMethod) => { it('throws error if wrapper array contains no items', () => { const compiled = compileToFunctions('
') const message = '[vue-test-utils]: contains cannot be called on 0 items' - expect(() => mountingMethod(compiled).findAll('p').contains('p')).to.throw().with.property('message', message) + expect(() => + mountingMethod(compiled) + .findAll('p') + .contains('p') + ) + .to.throw() + .with.property('message', message) }) it('throws error if selector is not a valid selector', () => { @@ -28,11 +38,24 @@ describeWithShallowAndMount('contains', (mountingMethod) => { const wrapper = mountingMethod(compiled) const pArr = wrapper.findAll('p') const invalidSelectors = [ - undefined, null, NaN, 0, 2, true, false, () => {}, {}, { name: undefined }, [] + undefined, + null, + NaN, + 0, + 2, + true, + false, + () => {}, + {}, + { name: undefined }, + [] ] - invalidSelectors.forEach((invalidSelector) => { - const message = '[vue-test-utils]: wrapper.contains() must be passed a valid CSS selector, Vue constructor, or valid find option object' - expect(() => pArr.contains(invalidSelector)).to.throw().with.property('message', message) + invalidSelectors.forEach(invalidSelector => { + const message = + '[vue-test-utils]: wrapper.contains() must be passed a valid CSS selector, Vue constructor, or valid find option object' + expect(() => pArr.contains(invalidSelector)) + .to.throw() + .with.property('message', message) }) }) }) diff --git a/test/specs/wrapper-array/find.spec.js b/test/specs/wrapper-array/find.spec.js index cd4162c17..a7d599e91 100644 --- a/test/specs/wrapper-array/find.spec.js +++ b/test/specs/wrapper-array/find.spec.js @@ -2,17 +2,28 @@ import { describeWithShallowAndMount } from '~resources/utils' import { compileToFunctions } from 'vue-template-compiler' import '~vue/test-utils' -describeWithShallowAndMount('find', (mountingMethod) => { +describeWithShallowAndMount('find', mountingMethod => { it('throws error if wrapper array contains no items', () => { const compiled = compileToFunctions('
') const message = '[vue-test-utils]: find cannot be called on 0 items' - expect(() => mountingMethod(compiled).findAll('p').find('p')).to.throw().with.property('message', message) + expect(() => + mountingMethod(compiled) + .findAll('p') + .find('p') + ) + .to.throw() + .with.property('message', message) }) it('throws an error when called on a WrapperArray', () => { - const compiled = compileToFunctions('

') + const compiled = compileToFunctions( + '

' + ) const wrapper = mountingMethod(compiled) - const message = '[vue-test-utils]: find must be called on a single wrapper, use at(i) to access a wrapper' - expect(() => wrapper.findAll('div').find('div')).to.throw().with.property('message', message) + const message = + '[vue-test-utils]: find must be called on a single wrapper, use at(i) to access a wrapper' + expect(() => wrapper.findAll('div').find('div')) + .to.throw() + .with.property('message', message) }) }) diff --git a/test/specs/wrapper-array/findAll.spec.js b/test/specs/wrapper-array/findAll.spec.js index 4a97e6202..cf4df7c99 100644 --- a/test/specs/wrapper-array/findAll.spec.js +++ b/test/specs/wrapper-array/findAll.spec.js @@ -2,17 +2,28 @@ import { describeWithShallowAndMount } from '~resources/utils' import { compileToFunctions } from 'vue-template-compiler' import '~vue/test-utils' -describeWithShallowAndMount('findAll', (mountingMethod) => { +describeWithShallowAndMount('findAll', mountingMethod => { it('throws error if wrapper array contains no items', () => { const compiled = compileToFunctions('
') const message = '[vue-test-utils]: findAll cannot be called on 0 items' - expect(() => mountingMethod(compiled).findAll('p').findAll('p')).to.throw().with.property('message', message) + expect(() => + mountingMethod(compiled) + .findAll('p') + .findAll('p') + ) + .to.throw() + .with.property('message', message) }) it('throws an error when called on a WrapperArray', () => { - const compiled = compileToFunctions('

') + const compiled = compileToFunctions( + '

' + ) const wrapper = mountingMethod(compiled) - const message = '[vue-test-utils]: findAll must be called on a single wrapper, use at(i) to access a wrapper' - expect(() => wrapper.findAll('div').findAll('div')).to.throw().with.property('message', message) + const message = + '[vue-test-utils]: findAll must be called on a single wrapper, use at(i) to access a wrapper' + expect(() => wrapper.findAll('div').findAll('div')) + .to.throw() + .with.property('message', message) }) }) diff --git a/test/specs/wrapper-array/hasAttribute.spec.js b/test/specs/wrapper-array/hasAttribute.spec.js index a1bf82bb6..1ac0429ce 100644 --- a/test/specs/wrapper-array/hasAttribute.spec.js +++ b/test/specs/wrapper-array/hasAttribute.spec.js @@ -2,41 +2,60 @@ import { describeWithShallowAndMount } from '~resources/utils' import { compileToFunctions } from 'vue-template-compiler' import '~vue/test-utils' -describeWithShallowAndMount('hasAttribute', (mountingMethod) => { +describeWithShallowAndMount('hasAttribute', mountingMethod => { it('returns true if every item contains attribute matching value', () => { const attribute = 'attribute' const value = 'value' - const compiled = compileToFunctions(`
`) + const compiled = compileToFunctions( + `
` + ) const wrapper = mountingMethod(compiled) - expect(wrapper.findAll('div').hasAttribute(attribute, value)).to.equal(true) + 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) + 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 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) + 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) + 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) + 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 index 8a8712564..ebb911986 100644 --- a/test/specs/wrapper-array/hasClass.spec.js +++ b/test/specs/wrapper-array/hasClass.spec.js @@ -2,7 +2,7 @@ import { describeWithShallowAndMount } from '~resources/utils' import { compileToFunctions } from 'vue-template-compiler' import '~vue/test-utils' -describeWithShallowAndMount('hasClass', (mountingMethod) => { +describeWithShallowAndMount('hasClass', mountingMethod => { it('returns true if every item has class name', () => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) @@ -18,19 +18,37 @@ describeWithShallowAndMount('hasClass', (mountingMethod) => { 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) + 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, () => {}, {}, [] + undefined, + null, + NaN, + 0, + 2, + true, + false, + () => {}, + {}, + [] ] - invalidSelectors.forEach((invalidSelector) => { - const message = '[vue-test-utils]: wrapper.hasClass() must be passed a string' + 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) + 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 index 716355a7c..94daafb23 100644 --- a/test/specs/wrapper-array/hasProp.spec.js +++ b/test/specs/wrapper-array/hasProp.spec.js @@ -3,34 +3,60 @@ import ComponentWithChild from '~resources/components/component-with-child.vue' import Component from '~resources/components/component.vue' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('hasProp', (mountingMethod) => { +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) + 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) + 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) + 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, () => {}, {}, [] + 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) + 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 index 52b26f96a..12ec64039 100644 --- a/test/specs/wrapper-array/hasStyle.spec.js +++ b/test/specs/wrapper-array/hasStyle.spec.js @@ -2,9 +2,11 @@ import { compileToFunctions } from 'vue-template-compiler' import ComponentWithStyle from '~resources/components/component-with-style.vue' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('hasStyle', (mountingMethod) => { +describeWithShallowAndMount('hasStyle', mountingMethod => { it('returns true if every item contains styles, set inline', () => { - const compiled = compileToFunctions('
') + const compiled = compileToFunctions( + '
' + ) const wrapper = mountingMethod(compiled) expect(wrapper.findAll('div').hasStyle('color', 'red')).to.equal(true) }) @@ -31,7 +33,9 @@ describeWithShallowAndMount('hasStyle', (mountingMethod) => { if (navigator.userAgent.includes && navigator.userAgent.includes('jsdom')) { return } - const wrapper = mountingMethod(ComponentWithStyle, { attachToDocument: true }) + 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) @@ -40,23 +44,34 @@ describeWithShallowAndMount('hasStyle', (mountingMethod) => { 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) + 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 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) + 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 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) + expect(fn) + .to.throw() + .with.property('message', message) }) }) diff --git a/test/specs/wrapper-array/html.spec.js b/test/specs/wrapper-array/html.spec.js index e35e632ff..f8a24ca53 100644 --- a/test/specs/wrapper-array/html.spec.js +++ b/test/specs/wrapper-array/html.spec.js @@ -2,18 +2,27 @@ import { describeWithShallowAndMount } from '~resources/utils' import { compileToFunctions } from 'vue-template-compiler' import '~vue/test-utils' -describeWithShallowAndMount('html', (mountingMethod) => { +describeWithShallowAndMount('html', mountingMethod => { it('throws error if wrapper array contains no items', () => { const compiled = compileToFunctions('
') const message = '[vue-test-utils]: html cannot be called on 0 items' - expect(() => mountingMethod(compiled).findAll('p').html('p')).to.throw().with.property('message', message) + expect(() => + mountingMethod(compiled) + .findAll('p') + .html('p') + ) + .to.throw() + .with.property('message', message) }) it('throws error when called on a WrapperArray', () => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) - const message = '[vue-test-utils]: html must be called on a single wrapper, use at(i) to access a wrapper' + const message = + '[vue-test-utils]: html must be called on a single wrapper, use at(i) to access a wrapper' const fn = () => wrapper.findAll('div').html() - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) }) }) diff --git a/test/specs/wrapper-array/is.spec.js b/test/specs/wrapper-array/is.spec.js index 5ed52c435..87b1bf682 100644 --- a/test/specs/wrapper-array/is.spec.js +++ b/test/specs/wrapper-array/is.spec.js @@ -3,7 +3,7 @@ import ComponentWithChild from '~resources/components/component-with-child.vue' import Component from '~resources/components/component.vue' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('is', (mountingMethod) => { +describeWithShallowAndMount('is', mountingMethod => { it('returns true if ech item matches selector', () => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) @@ -23,7 +23,9 @@ describeWithShallowAndMount('is', (mountingMethod) => { }) it('returns false if each item does not match tag selector', () => { - const compiled = compileToFunctions('
') + const compiled = compileToFunctions( + '
' + ) const wrapper = mountingMethod(compiled) expect(wrapper.findAll('div').is('.a-class')).to.equal(false) }) @@ -31,20 +33,38 @@ describeWithShallowAndMount('is', (mountingMethod) => { it('throws error if wrapper array contains no items', () => { const compiled = compileToFunctions('
') const message = '[vue-test-utils]: is cannot be called on 0 items' - const fn = () => mountingMethod(compiled).findAll('p').is('p') - expect(fn).to.throw().with.property('message', message) + const fn = () => + mountingMethod(compiled) + .findAll('p') + .is('p') + expect(fn) + .to.throw() + .with.property('message', message) }) it('throws error if selector is not a valid selector', () => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) const invalidSelectors = [ - undefined, null, NaN, 0, 2, true, false, () => {}, {}, { name: undefined }, [] + undefined, + null, + NaN, + 0, + 2, + true, + false, + () => {}, + {}, + { name: undefined }, + [] ] - invalidSelectors.forEach((invalidSelector) => { - const message = '[vue-test-utils]: wrapper.is() must be passed a valid CSS selector, Vue constructor, or valid find option object' + invalidSelectors.forEach(invalidSelector => { + const message = + '[vue-test-utils]: wrapper.is() must be passed a valid CSS selector, Vue constructor, or valid find option object' const fn = () => wrapper.findAll('div').is(invalidSelector) - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) }) }) }) diff --git a/test/specs/wrapper-array/isEmpty.spec.js b/test/specs/wrapper-array/isEmpty.spec.js index 222b3df36..4a024482c 100644 --- a/test/specs/wrapper-array/isEmpty.spec.js +++ b/test/specs/wrapper-array/isEmpty.spec.js @@ -2,7 +2,7 @@ import { describeWithShallowAndMount } from '~resources/utils' import { compileToFunctions } from 'vue-template-compiler' import '~vue/test-utils' -describeWithShallowAndMount('isEmpty', (mountingMethod) => { +describeWithShallowAndMount('isEmpty', mountingMethod => { it('returns true if node is empty', () => { const compiled = compileToFunctions('

') const wrapper = mountingMethod(compiled) @@ -20,7 +20,12 @@ describeWithShallowAndMount('isEmpty', (mountingMethod) => { it('throws error if wrapper array contains no items', () => { const compiled = compileToFunctions('
') const message = '[vue-test-utils]: isEmpty cannot be called on 0 items' - const fn = () => mountingMethod(compiled).findAll('p').isEmpty('p') - expect(fn).to.throw().with.property('message', message) + const fn = () => + mountingMethod(compiled) + .findAll('p') + .isEmpty('p') + expect(fn) + .to.throw() + .with.property('message', message) }) }) diff --git a/test/specs/wrapper-array/isVisible.spec.js b/test/specs/wrapper-array/isVisible.spec.js index c8bbc7ada..1063ee658 100644 --- a/test/specs/wrapper-array/isVisible.spec.js +++ b/test/specs/wrapper-array/isVisible.spec.js @@ -2,7 +2,7 @@ import { describeWithShallowAndMount } from '~resources/utils' import { compileToFunctions } from 'vue-template-compiler' import '~vue/test-utils' -describeWithShallowAndMount('isVisible', (mountingMethod) => { +describeWithShallowAndMount('isVisible', mountingMethod => { it('returns true if node has no inline style', () => { const compiled = compileToFunctions('

') const wrapper = mountingMethod(compiled) @@ -11,14 +11,18 @@ describeWithShallowAndMount('isVisible', (mountingMethod) => { }) it('returns false if node has inline style display: none', () => { - const compiled = compileToFunctions('

') + const compiled = compileToFunctions( + '

' + ) const wrapper = mountingMethod(compiled) expect(wrapper.findAll('p').isVisible()).to.equal(false) }) it('returns false if node has visibility: hidden', () => { - const compiled = compileToFunctions('

') + const compiled = compileToFunctions( + '

' + ) const wrapper = mountingMethod(compiled) expect(wrapper.findAll('p').isVisible()).to.equal(false) @@ -27,7 +31,12 @@ describeWithShallowAndMount('isVisible', (mountingMethod) => { it('throws error if wrapper array contains no items', () => { const compiled = compileToFunctions('
') const message = '[vue-test-utils]: isVisible cannot be called on 0 items' - const fn = () => mountingMethod(compiled).findAll('p').isVisible('p') - expect(fn).to.throw().with.property('message', message) + const fn = () => + mountingMethod(compiled) + .findAll('p') + .isVisible('p') + expect(fn) + .to.throw() + .with.property('message', message) }) }) diff --git a/test/specs/wrapper-array/isVueInstance.spec.js b/test/specs/wrapper-array/isVueInstance.spec.js index 11f1c8159..96c84d335 100644 --- a/test/specs/wrapper-array/isVueInstance.spec.js +++ b/test/specs/wrapper-array/isVueInstance.spec.js @@ -3,7 +3,7 @@ import ComponentWithChild from '~resources/components/component-with-child.vue' import Component from '~resources/components/component.vue' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('isVueInstance', (mountingMethod) => { +describeWithShallowAndMount('isVueInstance', mountingMethod => { it('returns true if wrapper is Vue instance', () => { const wrapper = mountingMethod(ComponentWithChild) expect(wrapper.findAll(Component).isVueInstance()).to.equal(true) @@ -17,8 +17,14 @@ describeWithShallowAndMount('isVueInstance', (mountingMethod) => { it('throws error if wrapper array contains no items', () => { const compiled = compileToFunctions('
') - const message = '[vue-test-utils]: isVueInstance cannot be called on 0 items' - const fn = () => mountingMethod(compiled).findAll('p').isVueInstance('p') - expect(fn).to.throw().with.property('message', message) + const message = + '[vue-test-utils]: isVueInstance cannot be called on 0 items' + const fn = () => + mountingMethod(compiled) + .findAll('p') + .isVueInstance('p') + expect(fn) + .to.throw() + .with.property('message', message) }) }) diff --git a/test/specs/wrapper-array/name.spec.js b/test/specs/wrapper-array/name.spec.js index 76b30bff1..50e33c4b2 100644 --- a/test/specs/wrapper-array/name.spec.js +++ b/test/specs/wrapper-array/name.spec.js @@ -2,18 +2,26 @@ import { describeWithShallowAndMount } from '~resources/utils' import { compileToFunctions } from 'vue-template-compiler' import '~vue/test-utils' -describeWithShallowAndMount('name', (mountingMethod) => { +describeWithShallowAndMount('name', mountingMethod => { it('throws an error when called on a WrapperArray', () => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) - const message = '[vue-test-utils]: name must be called on a single wrapper, use at(i) to access a wrapper' - expect(() => wrapper.findAll('div').name()).to.throw().with.property('message', message) + const message = + '[vue-test-utils]: name must be called on a single wrapper, use at(i) to access a wrapper' + expect(() => wrapper.findAll('div').name()) + .to.throw() + .with.property('message', message) }) it('throws error if wrapper array contains no items', () => { const compiled = compileToFunctions('
') const message = '[vue-test-utils]: name cannot be called on 0 items' - const fn = () => mountingMethod(compiled).findAll('p').name('p') - expect(fn).to.throw().with.property('message', message) + const fn = () => + mountingMethod(compiled) + .findAll('p') + .name('p') + expect(fn) + .to.throw() + .with.property('message', message) }) }) diff --git a/test/specs/wrapper-array/props.spec.js b/test/specs/wrapper-array/props.spec.js index e4ac79261..f7cb3956f 100644 --- a/test/specs/wrapper-array/props.spec.js +++ b/test/specs/wrapper-array/props.spec.js @@ -2,18 +2,27 @@ import { describeWithShallowAndMount } from '~resources/utils' import { compileToFunctions } from 'vue-template-compiler' import '~vue/test-utils' -describeWithShallowAndMount('props', (mountingMethod) => { +describeWithShallowAndMount('props', mountingMethod => { it('throws error if wrapper array contains no items', () => { const compiled = compileToFunctions('
') const message = '[vue-test-utils]: props cannot be called on 0 items' - expect(() => mountingMethod(compiled).findAll('p').props('p')).to.throw().with.property('message', message) + expect(() => + mountingMethod(compiled) + .findAll('p') + .props('p') + ) + .to.throw() + .with.property('message', message) }) it('throws error when called on a WrapperArray', () => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) - const message = '[vue-test-utils]: props must be called on a single wrapper, use at(i) to access a wrapper' + const message = + '[vue-test-utils]: props must be called on a single wrapper, use at(i) to access a wrapper' const fn = () => wrapper.findAll('div').props() - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) }) }) diff --git a/test/specs/wrapper-array/setData.spec.js b/test/specs/wrapper-array/setData.spec.js index fffd8dfbf..b0635da19 100644 --- a/test/specs/wrapper-array/setData.spec.js +++ b/test/specs/wrapper-array/setData.spec.js @@ -2,7 +2,7 @@ import { compileToFunctions } from 'vue-template-compiler' import ComponentWithVIf from '~resources/components/component-with-v-if.vue' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('setData', (mountingMethod) => { +describeWithShallowAndMount('setData', mountingMethod => { it('sets component data and updates nested vm nodes when called on Vue instance', () => { const TestComponent = { render: h => h(ComponentWithVIf) @@ -15,17 +15,25 @@ describeWithShallowAndMount('setData', (mountingMethod) => { }) it('throws an error if node is not a Vue instance', () => { - const message = '[vue-test-utils]: wrapper.setData() can only be called on a Vue instance' + const message = + '[vue-test-utils]: wrapper.setData() can only be called on a Vue instance' const compiled = compileToFunctions('

') const wrapper = mountingMethod(compiled) const fn = () => wrapper.findAll('p').setData({ ready: true }) - expect(fn).to.throw().with.property('message', message) + 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]: setData cannot be called on 0 items' - const fn = () => mountingMethod(compiled).findAll('p').setData('p') - expect(fn).to.throw().with.property('message', message) + const fn = () => + mountingMethod(compiled) + .findAll('p') + .setData('p') + expect(fn) + .to.throw() + .with.property('message', message) }) }) diff --git a/test/specs/wrapper-array/setProps.spec.js b/test/specs/wrapper-array/setProps.spec.js index 09fa5ccfd..0909d7a0e 100644 --- a/test/specs/wrapper-array/setProps.spec.js +++ b/test/specs/wrapper-array/setProps.spec.js @@ -2,7 +2,7 @@ import { compileToFunctions } from 'vue-template-compiler' import ComponentWithProps from '~resources/components/component-with-props.vue' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('setProps', (mountingMethod) => { +describeWithShallowAndMount('setProps', mountingMethod => { it('sets component props and updates DOM when called on Vue instance', () => { const prop1 = 'prop 1' const prop2 = 'prop 2' @@ -29,18 +29,26 @@ describeWithShallowAndMount('setProps', (mountingMethod) => { }) it('throws an error if node is not a Vue instance', () => { - const message = '[vue-test-utils]: wrapper.setProps() can only be called on a Vue instance' + const message = + '[vue-test-utils]: wrapper.setProps() can only be called on a Vue instance' const compiled = compileToFunctions('

') const wrapper = mountingMethod(compiled) const p = wrapper.findAll('p') const fn = () => p.setProps({ ready: true }) - expect(fn).to.throw().with.property('message', message) + 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]: setProps cannot be called on 0 items' - const fn = () => mountingMethod(compiled).findAll('p').setProps('p') - expect(fn).to.throw().with.property('message', message) + const fn = () => + mountingMethod(compiled) + .findAll('p') + .setProps('p') + expect(fn) + .to.throw() + .with.property('message', message) }) }) diff --git a/test/specs/wrapper-array/text.spec.js b/test/specs/wrapper-array/text.spec.js index ba7cb0e06..15b1a553b 100644 --- a/test/specs/wrapper-array/text.spec.js +++ b/test/specs/wrapper-array/text.spec.js @@ -2,19 +2,27 @@ import { describeWithShallowAndMount } from '~resources/utils' import { compileToFunctions } from 'vue-template-compiler' import '~vue/test-utils' -describeWithShallowAndMount('text', (mountingMethod) => { +describeWithShallowAndMount('text', mountingMethod => { it('throws error when called on a WrapperArray', () => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) - const message = '[vue-test-utils]: text must be called on a single wrapper, use at(i) to access a wrapper' + const message = + '[vue-test-utils]: text must be called on a single wrapper, use at(i) to access a wrapper' const fn = () => wrapper.findAll('div').text() - expect(fn).to.throw().with.property('message', message) + 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]: text cannot be called on 0 items' - const fn = () => mountingMethod(compiled).findAll('p').text('p') - expect(fn).to.throw().with.property('message', message) + const fn = () => + mountingMethod(compiled) + .findAll('p') + .text('p') + 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 a20865372..cc27da5cc 100644 --- a/test/specs/wrapper-array/trigger.spec.js +++ b/test/specs/wrapper-array/trigger.spec.js @@ -2,7 +2,7 @@ import { compileToFunctions } from 'vue-template-compiler' import ComponentWithEvents from '~resources/components/component-with-events.vue' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('trigger', (mountingMethod) => { +describeWithShallowAndMount('trigger', mountingMethod => { it('causes click handler to fire when wrapper.trigger("click") is called on a Component', () => { const clickHandler = sinon.stub() const wrapper = mountingMethod(ComponentWithEvents, { @@ -45,19 +45,36 @@ describeWithShallowAndMount('trigger', (mountingMethod) => { it('throws an error if type is not a string', () => { const wrapper = mountingMethod(ComponentWithEvents) const invalidSelectors = [ - undefined, null, NaN, 0, 2, true, false, () => {}, {}, [] + undefined, + null, + NaN, + 0, + 2, + true, + false, + () => {}, + {}, + [] ] - invalidSelectors.forEach((invalidSelector) => { - const message = '[vue-test-utils]: wrapper.trigger() must be passed a string' + invalidSelectors.forEach(invalidSelector => { + const message = + '[vue-test-utils]: wrapper.trigger() must be passed a string' const fn = () => wrapper.trigger(invalidSelector) - expect(fn).to.throw().with.property('message', message) + 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]: trigger cannot be called on 0 items' - const fn = () => mountingMethod(compiled).findAll('p').trigger('p') - expect(fn).to.throw().with.property('message', message) + const fn = () => + mountingMethod(compiled) + .findAll('p') + .trigger('p') + expect(fn) + .to.throw() + .with.property('message', message) }) }) diff --git a/test/specs/wrapper/at.spec.js b/test/specs/wrapper/at.spec.js index ade02cb24..005174445 100644 --- a/test/specs/wrapper/at.spec.js +++ b/test/specs/wrapper/at.spec.js @@ -1,12 +1,14 @@ import { compileToFunctions } from 'vue-template-compiler' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('at', (mountingMethod) => { +describeWithShallowAndMount('at', mountingMethod => { it('throws an error', () => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) const message = '[vue-test-utils]: at() must be called on a WrapperArray' const fn = () => wrapper.at() - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) }) }) diff --git a/test/specs/wrapper/attributes.spec.js b/test/specs/wrapper/attributes.spec.js index 08b9cbc13..e93b91bfb 100644 --- a/test/specs/wrapper/attributes.spec.js +++ b/test/specs/wrapper/attributes.spec.js @@ -1,7 +1,7 @@ import { compileToFunctions } from 'vue-template-compiler' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('attributes', (mountingMethod) => { +describeWithShallowAndMount('attributes', mountingMethod => { it('returns true if wrapper contains attribute matching value', () => { const attribute = 'attribute' const value = 'value' diff --git a/test/specs/wrapper/classes.spec.js b/test/specs/wrapper/classes.spec.js index 3dc6738be..d70bd6ae4 100644 --- a/test/specs/wrapper/classes.spec.js +++ b/test/specs/wrapper/classes.spec.js @@ -2,7 +2,7 @@ import { describeWithShallowAndMount } from '~resources/utils' import { compileToFunctions } from 'vue-template-compiler' import ComponentWithCssModules from '~resources/components/component-with-css-modules.vue' -describeWithShallowAndMount('classes', (mountingMethod) => { +describeWithShallowAndMount('classes', mountingMethod => { it('returns array of class names if wrapper has class names', () => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) @@ -22,7 +22,9 @@ describeWithShallowAndMount('classes', (mountingMethod) => { }) it('returns array of class names for svg element', () => { - const compiled = compileToFunctions('') + const compiled = compileToFunctions( + '' + ) const wrapper = mountingMethod(compiled) expect(wrapper.classes()).to.contain('a-class') expect(wrapper.classes()).to.contain('b-class') diff --git a/test/specs/wrapper/contains.spec.js b/test/specs/wrapper/contains.spec.js index 1abb600b3..fc04a7707 100644 --- a/test/specs/wrapper/contains.spec.js +++ b/test/specs/wrapper/contains.spec.js @@ -11,7 +11,7 @@ import { import { itSkipIf } from 'conditional-specs' import ComponentWithoutName from '~resources/components/component-without-name.vue' -describeWithShallowAndMount('contains', (mountingMethod) => { +describeWithShallowAndMount('contains', mountingMethod => { it('returns true if wrapper contains element', () => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) @@ -44,7 +44,8 @@ describeWithShallowAndMount('contains', (mountingMethod) => { itSkipIf( isRunningPhantomJS, - 'returns true if wrapper contains Vue class component', () => { + 'returns true if wrapper contains Vue class component', + () => { const TestComponent = { template: `
@@ -57,7 +58,8 @@ describeWithShallowAndMount('contains', (mountingMethod) => { } const wrapper = mountingMethod(TestComponent) expect(wrapper.contains(ComponentAsAClass)).to.equal(true) - }) + } + ) it('returns true if wrapper contains element specified by ref selector', () => { const compiled = compileToFunctions('
') @@ -69,9 +71,12 @@ describeWithShallowAndMount('contains', (mountingMethod) => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) const a = wrapper.find('a') - const message = '[vue-test-utils]: $ref selectors can only be used on Vue component wrappers' + const message = + '[vue-test-utils]: $ref selectors can only be used on Vue component wrappers' const fn = () => a.contains({ ref: 'foo' }) - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) }) it('returns true when wrapper contains root element', () => { @@ -136,12 +141,26 @@ describeWithShallowAndMount('contains', (mountingMethod) => { it('throws an error if selector is not a valid selector', () => { const wrapper = mountingMethod(Component) const invalidSelectors = [ - undefined, null, NaN, 0, 2, true, false, () => {}, {}, { name: undefined }, { ref: 'foo', nope: true }, [] + undefined, + null, + NaN, + 0, + 2, + true, + false, + () => {}, + {}, + { name: undefined }, + { ref: 'foo', nope: true }, + [] ] - invalidSelectors.forEach((invalidSelector) => { - const message = '[vue-test-utils]: wrapper.contains() must be passed a valid CSS selector, Vue constructor, or valid find option object' + invalidSelectors.forEach(invalidSelector => { + const message = + '[vue-test-utils]: wrapper.contains() must be passed a valid CSS selector, Vue constructor, or valid find option object' const fn = () => wrapper.contains(invalidSelector) - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) }) }) }) diff --git a/test/specs/wrapper/destroy.spec.js b/test/specs/wrapper/destroy.spec.js index a66e7721b..4fe466a34 100644 --- a/test/specs/wrapper/destroy.spec.js +++ b/test/specs/wrapper/destroy.spec.js @@ -2,7 +2,7 @@ import { compileToFunctions } from 'vue-template-compiler' import { describeWithShallowAndMount } from '~resources/utils' import sinon from 'sinon' -describeWithShallowAndMount('destroy', (mountingMethod) => { +describeWithShallowAndMount('destroy', mountingMethod => { it('triggers beforeDestroy ', () => { const spy = sinon.stub() mountingMethod({ diff --git a/test/specs/wrapper/emitted.spec.js b/test/specs/wrapper/emitted.spec.js index da0a98930..d337dfdaa 100644 --- a/test/specs/wrapper/emitted.spec.js +++ b/test/specs/wrapper/emitted.spec.js @@ -1,7 +1,7 @@ import { createLocalVue } from '~vue/test-utils' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('emitted', (mountingMethod) => { +describeWithShallowAndMount('emitted', mountingMethod => { it('captures emitted events with a different api', () => { const wrapper = mountingMethod({ render: h => h('div') @@ -50,10 +50,13 @@ describeWithShallowAndMount('emitted', (mountingMethod) => { const wrapper = mountingMethod({ template: '

' }) - const message = '[vue-test-utils]: wrapper.emitted() can only be called on a Vue instance' + const message = + '[vue-test-utils]: wrapper.emitted() can only be called on a Vue instance' const fn = () => wrapper.find('p').emitted() - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) }) it('captures all events thrown after beforeCreate lifecycle hook', () => { @@ -74,19 +77,25 @@ describeWithShallowAndMount('emitted', (mountingMethod) => { it('captures only events from its component without side effects on localVue', () => { const localVue = createLocalVue() - const wrapper1 = mountingMethod({ - render: () => {}, - beforeCreate () { - this.$emit('foo') - } - }, { localVue }) - - const wrapper2 = mountingMethod({ - render: () => {}, - mounted () { - this.$emit('bar') - } - }, { localVue }) + const wrapper1 = mountingMethod( + { + render: () => {}, + beforeCreate () { + this.$emit('foo') + } + }, + { localVue } + ) + + const wrapper2 = mountingMethod( + { + render: () => {}, + mounted () { + this.$emit('bar') + } + }, + { localVue } + ) expect(wrapper1.emitted().foo).to.eql([[]]) expect(wrapper1.emitted().bar).to.eql(undefined) diff --git a/test/specs/wrapper/emittedByOrder.spec.js b/test/specs/wrapper/emittedByOrder.spec.js index 2364a5a28..5c548395c 100644 --- a/test/specs/wrapper/emittedByOrder.spec.js +++ b/test/specs/wrapper/emittedByOrder.spec.js @@ -1,7 +1,7 @@ import Vue from 'vue' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('emittedByOrder', (mountingMethod) => { +describeWithShallowAndMount('emittedByOrder', mountingMethod => { it('captures emitted events in order', () => { const wrapper = mountingMethod({ render: h => h('div') @@ -34,10 +34,13 @@ describeWithShallowAndMount('emittedByOrder', (mountingMethod) => { const wrapper = mountingMethod({ template: '

' }) - const message = '[vue-test-utils]: wrapper.emittedByOrder() can only be called on a Vue instance' + const message = + '[vue-test-utils]: wrapper.emittedByOrder() can only be called on a Vue instance' const fn = () => wrapper.find('p').emittedByOrder() - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) }) it('captures in lifecycle hooks emitted events in order', () => { diff --git a/test/specs/wrapper/exists.spec.js b/test/specs/wrapper/exists.spec.js index f912d6b7b..8fd2b63d3 100644 --- a/test/specs/wrapper/exists.spec.js +++ b/test/specs/wrapper/exists.spec.js @@ -1,7 +1,7 @@ import { compileToFunctions } from 'vue-template-compiler' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('exists', (mountingMethod) => { +describeWithShallowAndMount('exists', mountingMethod => { it('returns true if called on Wrapper', () => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) diff --git a/test/specs/wrapper/filter.spec.js b/test/specs/wrapper/filter.spec.js index ac08fc391..876fe5582 100644 --- a/test/specs/wrapper/filter.spec.js +++ b/test/specs/wrapper/filter.spec.js @@ -1,12 +1,15 @@ import { compileToFunctions } from 'vue-template-compiler' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('filter', (mountingMethod) => { +describeWithShallowAndMount('filter', mountingMethod => { it('throws an error', () => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) - const message = '[vue-test-utils]: filter() must be called on a WrapperArray' + const message = + '[vue-test-utils]: filter() must be called on a WrapperArray' const fn = () => wrapper.filter() - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) }) }) diff --git a/test/specs/wrapper/find.spec.js b/test/specs/wrapper/find.spec.js index bf5e7ea22..fb7677f66 100644 --- a/test/specs/wrapper/find.spec.js +++ b/test/specs/wrapper/find.spec.js @@ -13,12 +13,9 @@ import { describeWithShallowAndMount, isRunningPhantomJS } from '~resources/utils' -import { - itDoNotRunIf, - itSkipIf -} from 'conditional-specs' +import { itDoNotRunIf, itSkipIf } from 'conditional-specs' -describeWithShallowAndMount('find', (mountingMethod) => { +describeWithShallowAndMount('find', mountingMethod => { it('returns a Wrapper matching tag selector passed', () => { const compiled = compileToFunctions('

') const wrapper = mountingMethod(compiled) @@ -39,14 +36,16 @@ describeWithShallowAndMount('find', (mountingMethod) => { itDoNotRunIf( isRunningPhantomJS, - 'returns an array of Wrapper of elements matching class selector passed if they are declared inside a slot', () => { + 'returns an array of Wrapper of elements matching class selector passed if they are declared inside a slot', + () => { const wrapper = mountingMethod(ComponentWithSlots, { slots: { default: '
' } }) expect(wrapper.find('.foo').vnode).to.be.an('object') - }) + } + ) it('returns Wrapper matching class selector passed if they are declared inside a functional component', () => { const Component = { @@ -54,7 +53,7 @@ describeWithShallowAndMount('find', (mountingMethod) => { render (h, { props }) { return h('div', {}, [ h('p', { - 'class': { + class: { foo: true } }), @@ -87,13 +86,18 @@ describeWithShallowAndMount('find', (mountingMethod) => { it('throws an error when passed an invalid DOM selector', () => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) - const message = '[vue-test-utils]: wrapper.find() must be passed a valid CSS selector, Vue constructor, or valid find option object' + const message = + '[vue-test-utils]: wrapper.find() must be passed a valid CSS selector, Vue constructor, or valid find option object' const fn = () => wrapper.find('[href=&6"/"]') - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) }) it('returns Wrapper of elements matching selector when descendant combinator passed', () => { - const compiled = compileToFunctions('
  • list
  • item
') + const compiled = compileToFunctions( + '
  • list
  • item
' + ) const wrapper = mountingMethod(compiled) expect(wrapper.find('div li').vnode).to.be.an('object') }) @@ -115,23 +119,21 @@ describeWithShallowAndMount('find', (mountingMethod) => { expect(wrapper.find(Component).vnode).to.be.an('object') }) - itSkipIf( - isRunningPhantomJS, - 'returns Wrapper of class component', () => { - const TestComponent = { - template: ` + itSkipIf(isRunningPhantomJS, 'returns Wrapper of class component', () => { + const TestComponent = { + template: `
`, - components: { - ComponentAsAClass - } + components: { + ComponentAsAClass } + } - const wrapper = mountingMethod(TestComponent) - expect(wrapper.find(ComponentAsAClass).vnode).to.be.an('object') - }) + const wrapper = mountingMethod(TestComponent) + expect(wrapper.find(ComponentAsAClass).vnode).to.be.an('object') + }) it('returns Wrapper of Vue Component matching functional component', () => { if (!functionalSFCsSupported) { @@ -167,9 +169,12 @@ describeWithShallowAndMount('find', (mountingMethod) => { } const wrapper = mountingMethod(TestComponent) if (vueVersion < 2.3) { - const message = '[vue-test-utils]: find for functional components is not support in Vue < 2.3' + const message = + '[vue-test-utils]: find for functional components is not support in Vue < 2.3' const fn = () => wrapper.find(TestFunctionalComponent) - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) } else { expect(wrapper.find(TestFunctionalComponent).exists()).to.equal(true) } @@ -186,7 +191,12 @@ describeWithShallowAndMount('find', (mountingMethod) => { } } const wrapper = mountingMethod(TestComponent) - expect(wrapper.find('svg').find('svg').exists()).to.equal(true) + expect( + wrapper + .find('svg') + .find('svg') + .exists() + ).to.equal(true) }) it('throws errror when searching for a component on an element Wrapper', () => { @@ -199,9 +209,15 @@ describeWithShallowAndMount('find', (mountingMethod) => { }) } } - const fn = () => mountingMethod(TestComponent).find('svg').find(Component) - const message = '[vue-test-utils]: cannot find a Vue instance on a DOM node. The node you are calling find on does not exist in the VDom. Are you adding the node as innerHTML?' - expect(fn).to.throw().with.property('message', message) + const fn = () => + mountingMethod(TestComponent) + .find('svg') + .find(Component) + const message = + '[vue-test-utils]: cannot find a Vue instance on a DOM node. The node you are calling find on does not exist in the VDom. Are you adding the node as innerHTML?' + expect(fn) + .to.throw() + .with.property('message', message) }) it('throws errror when using ref selector on an element Wrapper', () => { @@ -214,9 +230,15 @@ describeWithShallowAndMount('find', (mountingMethod) => { }) } } - const fn = () => mountingMethod(TestComponent).find('svg').find({ ref: 'some-ref' }) - const message = '[vue-test-utils]: cannot find a Vue instance on a DOM node. The node you are calling find on does not exist in the VDom. Are you adding the node as innerHTML?' - expect(fn).to.throw().with.property('message', message) + const fn = () => + mountingMethod(TestComponent) + .find('svg') + .find({ ref: 'some-ref' }) + const message = + '[vue-test-utils]: cannot find a Vue instance on a DOM node. The node you are calling find on does not exist in the VDom. Are you adding the node as innerHTML?' + expect(fn) + .to.throw() + .with.property('message', message) }) it('returns correct number of Vue Wrappers when component has a v-for', () => { @@ -296,7 +318,9 @@ describeWithShallowAndMount('find', (mountingMethod) => { it('returns a Wrapper matching a component name in options object', () => { const wrapper = mountingMethod(ComponentWithChild) - expect(wrapper.find({ name: 'test-component' }).name()).to.equal('test-component') + expect(wrapper.find({ name: 'test-component' }).name()).to.equal( + 'test-component' + ) }) it('returns Wrapper of Vue Component matching the ref in options object', () => { @@ -308,13 +332,18 @@ describeWithShallowAndMount('find', (mountingMethod) => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) const a = wrapper.find('a') - const message = '[vue-test-utils]: $ref selectors can only be used on Vue component wrappers' + const message = + '[vue-test-utils]: $ref selectors can only be used on Vue component wrappers' const fn = () => a.find({ ref: 'foo' }) - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) }) it('returns Wrapper matching ref selector in options object passed if nested in a transition', () => { - const compiled = compileToFunctions('
') + const compiled = compileToFunctions( + '
' + ) const wrapper = mountingMethod(compiled) expect(wrapper.find({ ref: 'foo' })).to.be.an('object') }) @@ -344,12 +373,26 @@ describeWithShallowAndMount('find', (mountingMethod) => { it('throws an error if selector is not a valid selector', () => { const wrapper = mountingMethod(Component) const invalidSelectors = [ - undefined, null, NaN, 0, 2, true, false, () => {}, {}, { name: undefined }, { ref: 'foo', nope: true }, [] + undefined, + null, + NaN, + 0, + 2, + true, + false, + () => {}, + {}, + { name: undefined }, + { ref: 'foo', nope: true }, + [] ] - invalidSelectors.forEach((invalidSelector) => { - const message = '[vue-test-utils]: wrapper.find() must be passed a valid CSS selector, Vue constructor, or valid find option object' + invalidSelectors.forEach(invalidSelector => { + const message = + '[vue-test-utils]: wrapper.find() must be passed a valid CSS selector, Vue constructor, or valid find option object' const fn = () => wrapper.find(invalidSelector) - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) }) }) }) diff --git a/test/specs/wrapper/findAll.spec.js b/test/specs/wrapper/findAll.spec.js index 115ea9941..7908fe6df 100644 --- a/test/specs/wrapper/findAll.spec.js +++ b/test/specs/wrapper/findAll.spec.js @@ -11,12 +11,9 @@ import { describeWithShallowAndMount, isRunningPhantomJS } from '~resources/utils' -import { - itDoNotRunIf, - itSkipIf -} from 'conditional-specs' +import { itDoNotRunIf, itSkipIf } from 'conditional-specs' -describeWithShallowAndMount('findAll', (mountingMethod) => { +describeWithShallowAndMount('findAll', mountingMethod => { it('returns an WrapperArray of elements matching tag selector passed', () => { const compiled = compileToFunctions('

') const wrapper = mountingMethod(compiled) @@ -40,7 +37,8 @@ describeWithShallowAndMount('findAll', (mountingMethod) => { itDoNotRunIf( isRunningPhantomJS, - 'returns an array of Wrapper of elements matching class selector passed if they are declared inside a slot', () => { + 'returns an array of Wrapper of elements matching class selector passed if they are declared inside a slot', + () => { const wrapper = mountingMethod(ComponentWithSlots, { slots: { default: '
' @@ -48,7 +46,8 @@ describeWithShallowAndMount('findAll', (mountingMethod) => { }) const fooArr = wrapper.findAll('.foo') expect(fooArr.length).to.equal(2) - }) + } + ) it('returns an array of Wrapper of elements matching class selector passed if they are declared inside a functional component', () => { const Component = { @@ -56,7 +55,7 @@ describeWithShallowAndMount('findAll', (mountingMethod) => { render (h) { return h('p', {}, [ h('p', { - 'class': { + class: { foo: true } }), @@ -101,20 +100,27 @@ describeWithShallowAndMount('findAll', (mountingMethod) => { it('throws an error when passed an invalid DOM selector', () => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) - const message = '[vue-test-utils]: wrapper.findAll() must be passed a valid CSS selector, Vue constructor, or valid find option object' + const message = + '[vue-test-utils]: wrapper.findAll() must be passed a valid CSS selector, Vue constructor, or valid find option object' const fn = () => wrapper.findAll('[href=&6"/"]') - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) }) it('returns an array of Wrappers of elements matching selector when descendant combinator passed', () => { - const compiled = compileToFunctions('
  • list
  • item
') + const compiled = compileToFunctions( + '
  • list
  • item
' + ) const wrapper = mountingMethod(compiled) const liArr = wrapper.findAll('div li') expect(liArr.length).to.equal(2) }) it('does not return duplicate nodes', () => { - const compiled = compileToFunctions('

') + const compiled = compileToFunctions( + '

' + ) const wrapper = mountingMethod(compiled) expect(wrapper.findAll('div p').length).to.equal(2) }) @@ -201,23 +207,21 @@ describeWithShallowAndMount('findAll', (mountingMethod) => { expect(wrapper.findAll(ComponentWithoutName).length).to.equal(3) }) - itSkipIf( - isRunningPhantomJS, - 'returns Wrapper of class component', () => { - const TestComponent = { - template: ` + itSkipIf(isRunningPhantomJS, 'returns Wrapper of class component', () => { + const TestComponent = { + template: `
`, - components: { - ComponentAsAClass - } + components: { + ComponentAsAClass } + } - const wrapper = mountingMethod(TestComponent) - expect(wrapper.findAll(ComponentAsAClass).length).to.equal(1) - }) + const wrapper = mountingMethod(TestComponent) + expect(wrapper.findAll(ComponentAsAClass).length).to.equal(1) + }) it('returns Wrapper of Vue Component matching functional component', () => { if (!functionalSFCsSupported) { @@ -263,13 +267,18 @@ describeWithShallowAndMount('findAll', (mountingMethod) => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) const a = wrapper.find('a') - const message = '[vue-test-utils]: $ref selectors can only be used on Vue component wrappers' + const message = + '[vue-test-utils]: $ref selectors can only be used on Vue component wrappers' const fn = () => a.findAll({ ref: 'foo' }) - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) }) it('returns an array of Wrapper of elements matching the ref in options object if they are nested in a transition', () => { - const compiled = compileToFunctions('
') + const compiled = compileToFunctions( + '
' + ) const wrapper = mountingMethod(compiled) const divArr = wrapper.findAll({ ref: 'foo' }) expect(divArr.length).to.equal(1) @@ -292,12 +301,26 @@ describeWithShallowAndMount('findAll', (mountingMethod) => { it('throws an error if selector is not a valid selector', () => { const wrapper = mountingMethod(Component) const invalidSelectors = [ - undefined, null, NaN, 0, 2, true, false, () => {}, {}, { name: undefined }, { ref: 'foo', nope: true }, [] + undefined, + null, + NaN, + 0, + 2, + true, + false, + () => {}, + {}, + { name: undefined }, + { ref: 'foo', nope: true }, + [] ] - invalidSelectors.forEach((invalidSelector) => { - const message = '[vue-test-utils]: wrapper.findAll() must be passed a valid CSS selector, Vue constructor, or valid find option object' + invalidSelectors.forEach(invalidSelector => { + const message = + '[vue-test-utils]: wrapper.findAll() must be passed a valid CSS selector, Vue constructor, or valid find option object' const fn = () => wrapper.findAll(invalidSelector) - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) }) }) }) diff --git a/test/specs/wrapper/hasAttribute.spec.js b/test/specs/wrapper/hasAttribute.spec.js index 4e0e6c30b..27cdad613 100644 --- a/test/specs/wrapper/hasAttribute.spec.js +++ b/test/specs/wrapper/hasAttribute.spec.js @@ -1,7 +1,7 @@ import { compileToFunctions } from 'vue-template-compiler' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('hasAttribute', (mountingMethod) => { +describeWithShallowAndMount('hasAttribute', mountingMethod => { it('returns true if wrapper contains attribute matching value', () => { const attribute = 'attribute' const value = 'value' @@ -26,16 +26,22 @@ describeWithShallowAndMount('hasAttribute', (mountingMethod) => { 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 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) + 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 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) + expect(fn) + .to.throw() + .with.property('message', message) }) }) diff --git a/test/specs/wrapper/hasClass.spec.js b/test/specs/wrapper/hasClass.spec.js index b846a2cae..b149f013d 100644 --- a/test/specs/wrapper/hasClass.spec.js +++ b/test/specs/wrapper/hasClass.spec.js @@ -2,7 +2,7 @@ import ComponentWithCssModules from '~resources/components/component-with-css-mo import { compileToFunctions } from 'vue-template-compiler' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('hasClass', (mountingMethod) => { +describeWithShallowAndMount('hasClass', mountingMethod => { it('returns true if wrapper has class name', () => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) @@ -25,12 +25,24 @@ describeWithShallowAndMount('hasClass', (mountingMethod) => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) const invalidSelectors = [ - undefined, null, NaN, 0, 2, true, false, () => {}, {}, [] + undefined, + null, + NaN, + 0, + 2, + true, + false, + () => {}, + {}, + [] ] - invalidSelectors.forEach((invalidSelector) => { - const message = '[vue-test-utils]: wrapper.hasClass() must be passed a string' + 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) + expect(fn) + .to.throw() + .with.property('message', message) }) }) diff --git a/test/specs/wrapper/hasProp.spec.js b/test/specs/wrapper/hasProp.spec.js index 6a1dbdd57..77c70d44e 100644 --- a/test/specs/wrapper/hasProp.spec.js +++ b/test/specs/wrapper/hasProp.spec.js @@ -2,7 +2,7 @@ import { compileToFunctions } from 'vue-template-compiler' import ComponentWithProps from '~resources/components/component-with-props.vue' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('hasProp', (mountingMethod) => { +describeWithShallowAndMount('hasProp', mountingMethod => { it('returns true if wrapper has prop', () => { const prop1 = {} const prop2 = 'a prop' @@ -20,22 +20,39 @@ describeWithShallowAndMount('hasProp', (mountingMethod) => { 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 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) + 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, () => {}, {}, [] + undefined, + null, + NaN, + 0, + 2, + true, + false, + () => {}, + {}, + [] ] - invalidSelectors.forEach((invalidSelector) => { - const message = '[vue-test-utils]: wrapper.hasProp() must be passed prop as a string' + 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) + expect(fn) + .to.throw() + .with.property('message', message) }) }) }) diff --git a/test/specs/wrapper/hasStyle.spec.js b/test/specs/wrapper/hasStyle.spec.js index 120e499ff..8188550f5 100644 --- a/test/specs/wrapper/hasStyle.spec.js +++ b/test/specs/wrapper/hasStyle.spec.js @@ -2,7 +2,7 @@ import { compileToFunctions } from 'vue-template-compiler' import ComponentWithStyle from '~resources/components/component-with-style.vue' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('hasStyle', (mountingMethod) => { +describeWithShallowAndMount('hasStyle', mountingMethod => { it('returns true when element contains styles, set inline', () => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) @@ -31,7 +31,9 @@ describeWithShallowAndMount('hasStyle', (mountingMethod) => { if (navigator.userAgent.includes && navigator.userAgent.includes('jsdom')) { return } - const wrapper = mountingMethod(ComponentWithStyle, { attachToDocument: true }) + 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) @@ -40,17 +42,23 @@ describeWithShallowAndMount('hasStyle', (mountingMethod) => { 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 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) + 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 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) + expect(fn) + .to.throw() + .with.property('message', message) }) it('return false when the style is a invalid prop name ', () => { diff --git a/test/specs/wrapper/html.spec.js b/test/specs/wrapper/html.spec.js index 71d241fda..538891032 100644 --- a/test/specs/wrapper/html.spec.js +++ b/test/specs/wrapper/html.spec.js @@ -3,7 +3,7 @@ import Component from '~resources/components/component.vue' import ComponentAsAClass from '~resources/components/component-as-a-class.vue' import { vueVersion, describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('html', (mountingMethod) => { +describeWithShallowAndMount('html', mountingMethod => { it('returns a VueWrappers HTML as a string', () => { const expectedHtml = '
' const wrapper = mountingMethod(Component) @@ -33,7 +33,8 @@ describeWithShallowAndMount('html', (mountingMethod) => { }) it('returns a Wrappers HTML as a string', () => { - const expectedHtml = '' + const expectedHtml = + '' const compiled = compileToFunctions(expectedHtml) const wrapper = mountingMethod(compiled) expect(wrapper.html()).to.equal(expectedHtml) diff --git a/test/specs/wrapper/is.spec.js b/test/specs/wrapper/is.spec.js index c6d412da6..ca1cc83bd 100644 --- a/test/specs/wrapper/is.spec.js +++ b/test/specs/wrapper/is.spec.js @@ -4,9 +4,12 @@ import Component from '~resources/components/component.vue' import ComponentWithoutName from '~resources/components/component-without-name.vue' import FunctionalComponent from '~resources/components/functional-component.vue' import ComponentAsAClass from '~resources/components/component-as-a-class.vue' -import { functionalSFCsSupported, describeWithShallowAndMount } from '~resources/utils' +import { + functionalSFCsSupported, + describeWithShallowAndMount +} from '~resources/utils' -describeWithShallowAndMount('is', (mountingMethod) => { +describeWithShallowAndMount('is', mountingMethod => { it('returns true if root node matches tag selector', () => { const compiled = compileToFunctions('') const wrapper = mountingMethod(compiled) @@ -103,21 +106,38 @@ describeWithShallowAndMount('is', (mountingMethod) => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) - const message = '[vue-test-utils]: $ref selectors can not be used with wrapper.is()' + const message = + '[vue-test-utils]: $ref selectors can not be used with wrapper.is()' const fn = () => wrapper.is({ ref: 'foo' }) - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) }) it('throws an error if selector is not a valid selector', () => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) const invalidSelectors = [ - undefined, null, NaN, 0, 2, true, false, () => {}, {}, { name: undefined }, { ref: 'foo', nope: true }, [] + undefined, + null, + NaN, + 0, + 2, + true, + false, + () => {}, + {}, + { name: undefined }, + { ref: 'foo', nope: true }, + [] ] - invalidSelectors.forEach((invalidSelector) => { - const message = '[vue-test-utils]: wrapper.is() must be passed a valid CSS selector, Vue constructor, or valid find option object' + invalidSelectors.forEach(invalidSelector => { + const message = + '[vue-test-utils]: wrapper.is() must be passed a valid CSS selector, Vue constructor, or valid find option object' const fn = () => wrapper.is(invalidSelector) - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) }) }) }) diff --git a/test/specs/wrapper/isEmpty.spec.js b/test/specs/wrapper/isEmpty.spec.js index 873683cfe..d3d56901e 100644 --- a/test/specs/wrapper/isEmpty.spec.js +++ b/test/specs/wrapper/isEmpty.spec.js @@ -5,7 +5,7 @@ import { } from '~resources/utils' import { itSkipIf } from 'conditional-specs' -describeWithShallowAndMount('isEmpty', (mountingMethod) => { +describeWithShallowAndMount('isEmpty', mountingMethod => { it('returns true if node is empty', () => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) @@ -19,21 +19,19 @@ describeWithShallowAndMount('isEmpty', (mountingMethod) => { expect(wrapper.isEmpty()).to.equal(true) }) - itSkipIf( - isRunningPhantomJS, - 'returns true if innerHTML is empty', () => { - const TestComponent = { - render (createElement) { - return createElement('div', { - domProps: { - innerHTML: '' - } - }) - } + itSkipIf(isRunningPhantomJS, 'returns true if innerHTML is empty', () => { + const TestComponent = { + render (createElement) { + return createElement('div', { + domProps: { + innerHTML: '' + } + }) } - const wrapper = mountingMethod(TestComponent) - expect(wrapper.find('svg').isEmpty()).to.equal(true) - }) + } + const wrapper = mountingMethod(TestComponent) + expect(wrapper.find('svg').isEmpty()).to.equal(true) + }) it('returns false if innerHTML is not empty', () => { const TestComponent = { diff --git a/test/specs/wrapper/isVisible.spec.js b/test/specs/wrapper/isVisible.spec.js index 13526ce59..780344ae0 100644 --- a/test/specs/wrapper/isVisible.spec.js +++ b/test/specs/wrapper/isVisible.spec.js @@ -3,23 +3,29 @@ import ComponentWithVShow from '~resources/components/component-with-v-show.vue' import ComponentWithVIf from '~resources/components/component-with-v-if.vue' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('isVisible', (mountingMethod) => { +describeWithShallowAndMount('isVisible', mountingMethod => { it('returns true if element has no inline style', () => { - const compiled = compileToFunctions('
') + const compiled = compileToFunctions( + '
' + ) const wrapper = mountingMethod(compiled) const element = wrapper.find('.visible') expect(element.isVisible()).to.equal(true) }) it('returns false if element has inline style display: none', () => { - const compiled = compileToFunctions('
') + const compiled = compileToFunctions( + '
' + ) const wrapper = mountingMethod(compiled) const element = wrapper.find('.visible') expect(element.isVisible()).to.equal(false) }) it('returns false if element has inline style visibility: hidden', () => { - const compiled = compileToFunctions('
') + const compiled = compileToFunctions( + '
' + ) const wrapper = mountingMethod(compiled) const element = wrapper.find('.visible') expect(element.isVisible()).to.equal(false) diff --git a/test/specs/wrapper/isVueInstance.spec.js b/test/specs/wrapper/isVueInstance.spec.js index 302780c19..f677a4d1f 100644 --- a/test/specs/wrapper/isVueInstance.spec.js +++ b/test/specs/wrapper/isVueInstance.spec.js @@ -1,7 +1,7 @@ import { describeWithShallowAndMount } from '~resources/utils' import { compileToFunctions } from 'vue-template-compiler' -describeWithShallowAndMount('isVueInstance', (mountingMethod) => { +describeWithShallowAndMount('isVueInstance', mountingMethod => { it('returns true if wrapper is Vue instance', () => { const compiled = compileToFunctions('
') const wrapper = mountingMethod(compiled) diff --git a/test/specs/wrapper/name.spec.js b/test/specs/wrapper/name.spec.js index c3a327d0e..d360c8c5d 100644 --- a/test/specs/wrapper/name.spec.js +++ b/test/specs/wrapper/name.spec.js @@ -2,7 +2,7 @@ import { compileToFunctions } from 'vue-template-compiler' import Component from '~resources/components/component.vue' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('name', (mountingMethod) => { +describeWithShallowAndMount('name', mountingMethod => { it('returns the name of the component it was called on', () => { const wrapper = mountingMethod(Component) expect(wrapper.name()).to.equal('test-component') diff --git a/test/specs/wrapper/props.spec.js b/test/specs/wrapper/props.spec.js index 731498507..b9d507093 100644 --- a/test/specs/wrapper/props.spec.js +++ b/test/specs/wrapper/props.spec.js @@ -6,7 +6,7 @@ import { } from '~resources/utils' import { itSkipIf } from 'conditional-specs' -describeWithShallowAndMount('props', (mountingMethod) => { +describeWithShallowAndMount('props', mountingMethod => { it('returns true if wrapper has prop', () => { const prop1 = {} const prop2 = 'string val' @@ -49,8 +49,10 @@ describeWithShallowAndMount('props', (mountingMethod) => { expect(wrapper.props().message).to.equal('hello') }) - itSkipIf(!functionalSFCsSupported, - 'works correctly a functional component', () => { + itSkipIf( + !functionalSFCsSupported, + 'works correctly a functional component', + () => { const FunctionalComponent = { render: h => h('div'), functional: true, @@ -67,17 +69,26 @@ describeWithShallowAndMount('props', (mountingMethod) => { } }) if (mountingMethod.name === 'mount') { - const message = '[vue-test-utils]: wrapper.props() cannot be called on a mounted functional component.' + const message = + '[vue-test-utils]: wrapper.props() cannot be called on a mounted functional component.' const fn = () => wrapper.find(FunctionalComponent).props() - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) } - }) + } + ) 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.props() must be called on a Vue instance' + const p = mountingMethod(compiled) + .findAll('p') + .at(0) + const message = + '[vue-test-utils]: wrapper.props() must be called on a Vue instance' const fn = () => p.props() - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) }) }) diff --git a/test/specs/wrapper/setChecked.spec.js b/test/specs/wrapper/setChecked.spec.js index 116d06a7b..2cbd6da16 100644 --- a/test/specs/wrapper/setChecked.spec.js +++ b/test/specs/wrapper/setChecked.spec.js @@ -1,7 +1,7 @@ import ComponentWithInput from '~resources/components/component-with-input.vue' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('setChecked', (mountingMethod) => { +describeWithShallowAndMount('setChecked', mountingMethod => { it('sets element checked true with no option passed', () => { const wrapper = mountingMethod(ComponentWithInput) const input = wrapper.find('input[type="checkbox"]') @@ -78,27 +78,33 @@ describeWithShallowAndMount('setChecked', (mountingMethod) => { }) it('throws error if checked param is false on radio element', () => { - const message = 'wrapper.setChecked() cannot be called with parameter false on a element.' + const message = + 'wrapper.setChecked() cannot be called with parameter false on a element.' shouldThrowErrorOnElement('#radioFoo', message, false) }) it('throws error if wrapper does not contain element', () => { - const wrapper = mountingMethod({ render: (h) => h('div') }) + const wrapper = mountingMethod({ render: h => h('div') }) const div = wrapper.find('div') div.element = null const fn = () => div.setChecked() - const message = '[vue-test-utils]: cannot call wrapper.setChecked() on a wrapper without an element' - expect(fn).to.throw().with.property('message', message) + const message = + '[vue-test-utils]: cannot call wrapper.setChecked() on a wrapper without an element' + expect(fn) + .to.throw() + .with.property('message', message) }) it('throws error if element is select', () => { - const message = 'wrapper.setChecked() cannot be called on a element. Use wrapper.setSelected() instead' shouldThrowErrorOnElement('select', message) }) it('throws error if element is text like', () => { - const message = 'wrapper.setChecked() cannot be called on "text" inputs. Use wrapper.setValue() instead' + const message = + 'wrapper.setChecked() cannot be called on "text" inputs. Use wrapper.setValue() instead' shouldThrowErrorOnElement('input[type="text"]', message) }) @@ -112,6 +118,8 @@ describeWithShallowAndMount('setChecked', (mountingMethod) => { const input = wrapper.find(selector) const fn = () => input.setChecked(value) - expect(fn).to.throw().with.property('message', '[vue-test-utils]: ' + message) + expect(fn) + .to.throw() + .with.property('message', '[vue-test-utils]: ' + message) } }) diff --git a/test/specs/wrapper/setComputed.spec.js b/test/specs/wrapper/setComputed.spec.js index b4609f130..6744234e3 100644 --- a/test/specs/wrapper/setComputed.spec.js +++ b/test/specs/wrapper/setComputed.spec.js @@ -5,7 +5,7 @@ import ComponentWithComputed from '~resources/components/component-with-computed import ComponentWithWatch from '~resources/components/component-with-watch.vue' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('setComputed', (mountingMethod) => { +describeWithShallowAndMount('setComputed', mountingMethod => { let info beforeEach(() => { @@ -24,7 +24,8 @@ describeWithShallowAndMount('setComputed', (mountingMethod) => { }) 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 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) }) @@ -67,13 +68,9 @@ describeWithShallowAndMount('setComputed', (mountingMethod) => { }) const TestComponent = { computed: { - ...mapGetters([ - 'someGetter' - ]), + ...mapGetters(['someGetter']), placeholder () { - return this.someGetter - ? 'someGetter is true' - : 'someGetter is false' + return this.someGetter ? 'someGetter is true' : 'someGetter is false' } } } @@ -86,7 +83,8 @@ describeWithShallowAndMount('setComputed', (mountingMethod) => { }) it('throws an error if node is not a Vue instance', () => { - const message = 'wrapper.setComputed() can only be called on 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') diff --git a/test/specs/wrapper/setData.spec.js b/test/specs/wrapper/setData.spec.js index d5f69a82d..feba76ac9 100644 --- a/test/specs/wrapper/setData.spec.js +++ b/test/specs/wrapper/setData.spec.js @@ -1,12 +1,9 @@ import { compileToFunctions } from 'vue-template-compiler' import ComponentWithVIf from '~resources/components/component-with-v-if.vue' import ComponentWithWatch from '~resources/components/component-with-watch.vue' -import { - describeWithShallowAndMount, - vueVersion -} from '~resources/utils' +import { describeWithShallowAndMount, vueVersion } from '~resources/utils' -describeWithShallowAndMount('setData', (mountingMethod) => { +describeWithShallowAndMount('setData', mountingMethod => { let info beforeEach(() => { @@ -66,9 +63,13 @@ describeWithShallowAndMount('setData', (mountingMethod) => { render: (h, context) => h('div', context.prop1), functional: true } - const message = '[vue-test-utils]: wrapper.setData() cannot be called on a functional component' - const fn = () => mountingMethod(AFunctionalComponent).setData({ data1: 'data' }) - expect(fn).to.throw().with.property('message', message) + const message = + '[vue-test-utils]: wrapper.setData() cannot be called on a functional component' + const fn = () => + mountingMethod(AFunctionalComponent).setData({ data1: 'data' }) + expect(fn) + .to.throw() + .with.property('message', message) // find on functional components isn't supported in Vue < 2.3 if (vueVersion < 2.3) { return @@ -79,8 +80,13 @@ describeWithShallowAndMount('setData', (mountingMethod) => { AFunctionalComponent } } - const fn2 = () => mountingMethod(TestComponent).find(AFunctionalComponent).setData({ data1: 'data' }) - expect(fn2).to.throw().with.property('message', message) + const fn2 = () => + mountingMethod(TestComponent) + .find(AFunctionalComponent) + .setData({ data1: 'data' }) + expect(fn2) + .to.throw() + .with.property('message', message) }) it('updates watchers if computed is updated', () => { @@ -124,7 +130,10 @@ describeWithShallowAndMount('setData', (mountingMethod) => { }), computed: { reversedMessage: function () { - return this.message.split('').reverse().join('') + return this.message + .split('') + .reverse() + .join('') } } } diff --git a/test/specs/wrapper/setMethods.spec.js b/test/specs/wrapper/setMethods.spec.js index 9a252ee8c..8eef77da6 100644 --- a/test/specs/wrapper/setMethods.spec.js +++ b/test/specs/wrapper/setMethods.spec.js @@ -3,7 +3,7 @@ import ComponentWithMethods from '~resources/components/component-with-methods.v import ComponentWithEvents from '~resources/components/component-with-events.vue' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('setMethods', (mountingMethod) => { +describeWithShallowAndMount('setMethods', mountingMethod => { it('sets component data and updates nested vm nodes when called on Vue instance', () => { const wrapper = mountingMethod(ComponentWithMethods) const someMethod = () => console.log('hey') diff --git a/test/specs/wrapper/setProps.spec.js b/test/specs/wrapper/setProps.spec.js index 83d10635a..7e5852c83 100644 --- a/test/specs/wrapper/setProps.spec.js +++ b/test/specs/wrapper/setProps.spec.js @@ -1,12 +1,9 @@ import { compileToFunctions } from 'vue-template-compiler' import ComponentWithProps from '~resources/components/component-with-props.vue' import ComponentWithWatch from '~resources/components/component-with-watch.vue' -import { - describeWithShallowAndMount, - vueVersion -} from '~resources/utils' +import { describeWithShallowAndMount, vueVersion } from '~resources/utils' -describeWithShallowAndMount('setProps', (mountingMethod) => { +describeWithShallowAndMount('setProps', mountingMethod => { let info beforeEach(() => { @@ -31,9 +28,12 @@ describeWithShallowAndMount('setProps', (mountingMethod) => { const TestComponent = { template: '
' } - const message = '[vue-test-utils]: wrapper.setProps() called with prop1 property which is not defined on component' + const message = `[vue-test-utils]: wrapper.setProps() called ` + + `with prop1 property which is not defined on the component` const fn = () => mountingMethod(TestComponent).setProps({ prop1: 'prop' }) - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) }) it('throws error when called on functional vnode', () => { @@ -41,9 +41,13 @@ describeWithShallowAndMount('setProps', (mountingMethod) => { render: (h, context) => h('div', context.prop1), functional: true } - const message = '[vue-test-utils]: wrapper.setProps() cannot be called on a functional component' - const fn = () => mountingMethod(AFunctionalComponent).setProps({ prop1: 'prop' }) - expect(fn).to.throw().with.property('message', message) + const message = + '[vue-test-utils]: wrapper.setProps() cannot be called on a functional component' + const fn = () => + mountingMethod(AFunctionalComponent).setProps({ prop1: 'prop' }) + expect(fn) + .to.throw() + .with.property('message', message) // find on functional components isn't supported in Vue < 2.3 if (vueVersion < 2.3) { return @@ -54,8 +58,13 @@ describeWithShallowAndMount('setProps', (mountingMethod) => { AFunctionalComponent } } - const fn2 = () => mountingMethod(TestComponent).find(AFunctionalComponent).setProps({ prop1: 'prop' }) - expect(fn2).to.throw().with.property('message', message) + const fn2 = () => + mountingMethod(TestComponent) + .find(AFunctionalComponent) + .setProps({ prop1: 'prop' }) + expect(fn2) + .to.throw() + .with.property('message', message) }) it('sets component props, and updates DOM when propsData was not initially passed', () => { @@ -91,7 +100,10 @@ describeWithShallowAndMount('setProps', (mountingMethod) => { `, computed: { reversedMessage: function () { - return this.message.split('').reverse().join('') + return this.message + .split('') + .reverse() + .join('') } }, props: ['message'] diff --git a/test/specs/wrapper/setSelected.spec.js b/test/specs/wrapper/setSelected.spec.js index 4dc9f6503..f60b3ed26 100644 --- a/test/specs/wrapper/setSelected.spec.js +++ b/test/specs/wrapper/setSelected.spec.js @@ -1,7 +1,7 @@ import ComponentWithInput from '~resources/components/component-with-input.vue' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('setSelected', (mountingMethod) => { +describeWithShallowAndMount('setSelected', mountingMethod => { it('sets element selected true', () => { const wrapper = mountingMethod(ComponentWithInput) const options = wrapper.find('select').findAll('option') @@ -34,27 +34,33 @@ describeWithShallowAndMount('setSelected', (mountingMethod) => { }) it('throws error if wrapper does not contain element', () => { - const wrapper = mountingMethod({ render: (h) => h('div') }) + const wrapper = mountingMethod({ render: h => h('div') }) const div = wrapper.find('div') div.element = null const fn = () => div.setSelected() - const message = '[vue-test-utils]: cannot call wrapper.setSelected() on a wrapper without an element' - expect(fn).to.throw().with.property('message', message) + const message = + '[vue-test-utils]: cannot call wrapper.setSelected() on a wrapper without an element' + expect(fn) + .to.throw() + .with.property('message', message) }) it('throws error if element is radio', () => { - const message = 'wrapper.setSelected() cannot be called on a element. Use wrapper.setChecked() instead' + const message = + 'wrapper.setSelected() cannot be called on a element. Use wrapper.setChecked() instead' shouldThrowErrorOnElement('input[type="radio"]', message) }) it('throws error if element is radio', () => { - const message = 'wrapper.setSelected() cannot be called on a element. Use wrapper.setChecked() instead' + const message = + 'wrapper.setSelected() cannot be called on a element. Use wrapper.setChecked() instead' shouldThrowErrorOnElement('input[type="checkbox"]', message) }) it('throws error if element is text like', () => { - const message = 'wrapper.setSelected() cannot be called on "text" inputs. Use wrapper.setValue() instead' + const message = + 'wrapper.setSelected() cannot be called on "text" inputs. Use wrapper.setValue() instead' shouldThrowErrorOnElement('input[type="text"]', message) }) @@ -68,6 +74,8 @@ describeWithShallowAndMount('setSelected', (mountingMethod) => { const input = wrapper.find(selector) const fn = () => input.setSelected(value) - expect(fn).to.throw().with.property('message', '[vue-test-utils]: ' + message) + expect(fn) + .to.throw() + .with.property('message', '[vue-test-utils]: ' + message) } }) diff --git a/test/specs/wrapper/setValue.spec.js b/test/specs/wrapper/setValue.spec.js index f913575c0..228c658fc 100644 --- a/test/specs/wrapper/setValue.spec.js +++ b/test/specs/wrapper/setValue.spec.js @@ -1,7 +1,7 @@ import ComponentWithInput from '~resources/components/component-with-input.vue' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('setValue', (mountingMethod) => { +describeWithShallowAndMount('setValue', mountingMethod => { it('sets element value', () => { const wrapper = mountingMethod(ComponentWithInput) const input = wrapper.find('input[type="text"]') @@ -20,26 +20,32 @@ describeWithShallowAndMount('setValue', (mountingMethod) => { }) it('throws error if wrapper does not contain element', () => { - const wrapper = mountingMethod({ render: (h) => h('div') }) + const wrapper = mountingMethod({ render: h => h('div') }) const div = wrapper.find('div') div.element = null const fn = () => div.setValue('') - const message = '[vue-test-utils]: cannot call wrapper.setValue() on a wrapper without an element' - expect(fn).to.throw().with.property('message', message) + const message = + '[vue-test-utils]: cannot call wrapper.setValue() on a wrapper without an element' + expect(fn) + .to.throw() + .with.property('message', message) }) it('throws error if element is select', () => { - const message = 'wrapper.setValue() cannot be called on a element. Use wrapper.setSelected() instead' shouldThrowErrorOnElement('select', message) }) it('throws error if element is radio', () => { - const message = 'wrapper.setValue() cannot be called on a element. Use wrapper.setChecked() instead' + const message = + 'wrapper.setValue() cannot be called on a element. Use wrapper.setChecked() instead' shouldThrowErrorOnElement('input[type="radio"]', message) }) it('throws error if element is checkbox', () => { - const message = 'wrapper.setValue() cannot be called on a element. Use wrapper.setChecked() instead' + const message = + 'wrapper.setValue() cannot be called on a element. Use wrapper.setChecked() instead' shouldThrowErrorOnElement('input[type="checkbox"]', message) }) @@ -53,6 +59,8 @@ describeWithShallowAndMount('setValue', (mountingMethod) => { const input = wrapper.find(selector) const fn = () => input.setValue('') - expect(fn).to.throw().with.property('message', '[vue-test-utils]: ' + message) + expect(fn) + .to.throw() + .with.property('message', '[vue-test-utils]: ' + message) } }) diff --git a/test/specs/wrapper/text.spec.js b/test/specs/wrapper/text.spec.js index ff9073384..72634eddb 100644 --- a/test/specs/wrapper/text.spec.js +++ b/test/specs/wrapper/text.spec.js @@ -1,7 +1,7 @@ import { compileToFunctions } from 'vue-template-compiler' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('text', (mountingMethod) => { +describeWithShallowAndMount('text', mountingMethod => { it('returns text content of wrapper node', () => { const text = 'test text prop' const compiled = compileToFunctions(`
${text}
`) @@ -22,11 +22,14 @@ describeWithShallowAndMount('text', (mountingMethod) => { }) 152 it('throws error if wrapper does not contain element', () => { - const wrapper = mountingMethod({ render: (h) => h('div') }) + const wrapper = mountingMethod({ render: h => h('div') }) const div = wrapper.find('div') div.element = null const fn = () => div.text() - const message = '[vue-test-utils]: cannot call wrapper.text() on a wrapper without an element' - expect(fn).to.throw().with.property('message', message) + const message = + '[vue-test-utils]: cannot call wrapper.text() on a wrapper without an element' + expect(fn) + .to.throw() + .with.property('message', message) }) }) diff --git a/test/specs/wrapper/trigger.spec.js b/test/specs/wrapper/trigger.spec.js index 247b4b520..9b102ad14 100644 --- a/test/specs/wrapper/trigger.spec.js +++ b/test/specs/wrapper/trigger.spec.js @@ -7,7 +7,7 @@ import { import Vue from 'vue' import { itDoNotRunIf } from 'conditional-specs' -describeWithShallowAndMount('trigger', (mountingMethod) => { +describeWithShallowAndMount('trigger', mountingMethod => { let info beforeEach(() => { @@ -124,7 +124,8 @@ describeWithShallowAndMount('trigger', (mountingMethod) => { itDoNotRunIf( !scopedSlotsSupported, - 'handles instances without update watchers', () => { + 'handles instances without update watchers', + () => { const vm = new Vue() const item = () => vm.$createElement('button') const TestComponent = { @@ -139,36 +140,56 @@ describeWithShallowAndMount('trigger', (mountingMethod) => { const wrapper = mountingMethod(TestComponent) wrapper.findAll('button').trigger('click') - }) + } + ) it('throws error if options contains a target value', () => { - const wrapper = mountingMethod({ render: (h) => h('div') }) + const wrapper = mountingMethod({ render: h => h('div') }) const div = wrapper.find('div') - const fn = () => div.trigger('click', { - target: {} - }) - const message = '[vue-test-utils]: you cannot set the target value of an event. See the notes section of the docs for more details—https://vue-test-utils.vuejs.org/api/wrapper/trigger.html' - expect(fn).to.throw().with.property('message', message) + const fn = () => + div.trigger('click', { + target: {} + }) + const message = + '[vue-test-utils]: you cannot set the target value of an event. See the notes section of the docs for more details—https://vue-test-utils.vuejs.org/api/wrapper/trigger.html' + expect(fn) + .to.throw() + .with.property('message', message) }) it('throws error if wrapper does not contain element', () => { - const wrapper = mountingMethod({ render: (h) => h('div') }) + const wrapper = mountingMethod({ render: h => h('div') }) const div = wrapper.find('div') div.element = null const fn = () => div.trigger('click') - const message = '[vue-test-utils]: cannot call wrapper.trigger() on a wrapper without an element' - expect(fn).to.throw().with.property('message', message) + const message = + '[vue-test-utils]: cannot call wrapper.trigger() on a wrapper without an element' + expect(fn) + .to.throw() + .with.property('message', message) }) it('throws an error if type is not a string', () => { const wrapper = mountingMethod(ComponentWithEvents) const invalidSelectors = [ - undefined, null, NaN, 0, 2, true, false, () => {}, {}, [] + undefined, + null, + NaN, + 0, + 2, + true, + false, + () => {}, + {}, + [] ] - invalidSelectors.forEach((invalidSelector) => { - const message = '[vue-test-utils]: wrapper.trigger() must be passed a string' + invalidSelectors.forEach(invalidSelector => { + const message = + '[vue-test-utils]: wrapper.trigger() must be passed a string' const fn = () => wrapper.trigger(invalidSelector) - expect(fn).to.throw().with.property('message', message) + expect(fn) + .to.throw() + .with.property('message', message) }) }) })