From d7b36605c37b13f6f2fe21c0f40812fa3b0c2a05 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 5 May 2018 15:31:48 +0100 Subject: [PATCH 1/5] fix: only order deps if watcher exists --- packages/server-test-utils/scripts/build.js | 1 + packages/test-utils/scripts/build.js | 1 + packages/test-utils/src/order-watchers.js | 2 +- test/specs/wrapper/trigger.spec.js | 19 +++++++++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/server-test-utils/scripts/build.js b/packages/server-test-utils/scripts/build.js index 2c0a76d81..306de35f4 100644 --- a/packages/server-test-utils/scripts/build.js +++ b/packages/server-test-utils/scripts/build.js @@ -57,5 +57,6 @@ rollupOptions.forEach(options => { .then(() => success(`${options.format} build successful`)) .catch((err) => { error(err) + process.exit(1) }) }) diff --git a/packages/test-utils/scripts/build.js b/packages/test-utils/scripts/build.js index 92a6e33b0..6198c6232 100644 --- a/packages/test-utils/scripts/build.js +++ b/packages/test-utils/scripts/build.js @@ -70,5 +70,6 @@ rollupOptions.forEach(options => { .then(() => success(`${options.format} build successful`)) .catch((err) => { error(err) + process.exit(1) }) }) diff --git a/packages/test-utils/src/order-watchers.js b/packages/test-utils/src/order-watchers.js index 371b11014..3563aedc8 100644 --- a/packages/test-utils/src/order-watchers.js +++ b/packages/test-utils/src/order-watchers.js @@ -22,7 +22,7 @@ function orderVmWatchers (vm) { }) } - orderDeps(vm._watcher) + vm._watcher && orderDeps(vm._watcher) vm.$children.forEach(orderVmWatchers) } diff --git a/test/specs/wrapper/trigger.spec.js b/test/specs/wrapper/trigger.spec.js index df112b146..82813a3dd 100644 --- a/test/specs/wrapper/trigger.spec.js +++ b/test/specs/wrapper/trigger.spec.js @@ -1,5 +1,7 @@ import ComponentWithEvents from '~resources/components/component-with-events.vue' +import ComponentWithScopedSlots from '~resources/components/component-with-scoped-slots.vue' import { describeWithShallowAndMount } from '~resources/utils' +import Vue from 'vue' describeWithShallowAndMount('trigger', (mountingMethod) => { let info @@ -116,6 +118,23 @@ describeWithShallowAndMount('trigger', (mountingMethod) => { wrapper.trigger('keydown') }) + it('handles instances without update watchers', () => { + const vm = new Vue() + const item = () => vm.$createElement('button') + const TestComponent = { + render (h) { + return h(ComponentWithScopedSlots, { + scopedSlots: { + noProps: item + } + }) + } + } + 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 div = wrapper.find('div') From a4a55d08c31afe92d7d9dd4bffe301a22c51e2e0 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 5 May 2018 15:48:21 +0100 Subject: [PATCH 2/5] test: fix setProps watchers order --- packages/test-utils/src/wrapper.js | 1 + test/specs/wrapper/setProps.spec.js | 38 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/packages/test-utils/src/wrapper.js b/packages/test-utils/src/wrapper.js index 330ee1968..f050c1da3 100644 --- a/packages/test-utils/src/wrapper.js +++ b/packages/test-utils/src/wrapper.js @@ -537,6 +537,7 @@ export default class Wrapper implements BaseWrapper { // $FlowIgnore : Problem with possibly null this.vm this.vnode = this.vm._vnode + orderWatchers(this.vm || this.vnode.context.$root) } /** diff --git a/test/specs/wrapper/setProps.spec.js b/test/specs/wrapper/setProps.spec.js index 89ab74670..1f7524b4f 100644 --- a/test/specs/wrapper/setProps.spec.js +++ b/test/specs/wrapper/setProps.spec.js @@ -105,6 +105,44 @@ describeWithShallowAndMount('setProps', (mountingMethod) => { expect(wrapper.text()).to.equal('There is no message yet') }) + it.only('runs watchers correctly', () => { + const TestComponent = { + template: `
+ {{ stringified }} +
`, + props: ['collection'], + data: () => ({ + data: '' + }), + computed: { + stringified () { + return this.collection.join(',') + } + }, + watch: { + collection: 'execute' + }, + methods: { + execute () { + this.data = this.stringified + } + } + } + const wrapper = mountingMethod(TestComponent, { + propsData: { collection: [] } + }) + expect(wrapper.vm.stringified).to.equal('') + expect(wrapper.vm.data).to.equal('') + + wrapper.setProps({ collection: [1, 2, 3] }) + expect(wrapper.vm.stringified).to.equal('1,2,3') + expect(wrapper.vm.data).to.equal('1,2,3') + + wrapper.vm.collection.push(4, 5) + expect(wrapper.vm.stringified).to.equal('1,2,3,4,5') + expect(wrapper.vm.data).to.equal('1,2,3,4,5') + }) + it('throws an error if node is not a Vue instance', () => { const message = 'wrapper.setProps() can only be called on a Vue instance' const compiled = compileToFunctions('

') From c1b69c7b6696fe7f032a32c553d07c9822444e7c Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 5 May 2018 16:01:47 +0100 Subject: [PATCH 3/5] test: skip if scoped slots not supported --- test/resources/utils.js | 4 ++++ test/specs/wrapper/trigger.spec.js | 36 +++++++++++++++++------------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/test/resources/utils.js b/test/resources/utils.js index 58e062eb1..961c51445 100644 --- a/test/resources/utils.js +++ b/test/resources/utils.js @@ -32,6 +32,10 @@ export function functionalSFCsSupported () { return vueVersion >= 2.5 } +export function scopedSlotsSupported () { + return vueVersion >= 2.1 +} + const shallowAndMount = process.env.TEST_ENV === 'node' ? [] : [mount, shallow] diff --git a/test/specs/wrapper/trigger.spec.js b/test/specs/wrapper/trigger.spec.js index 82813a3dd..22c9d254d 100644 --- a/test/specs/wrapper/trigger.spec.js +++ b/test/specs/wrapper/trigger.spec.js @@ -1,6 +1,10 @@ import ComponentWithEvents from '~resources/components/component-with-events.vue' import ComponentWithScopedSlots from '~resources/components/component-with-scoped-slots.vue' -import { describeWithShallowAndMount } from '~resources/utils' +import { + describeWithShallowAndMount, + itDoNotRunIf, + scopedSlotsSupported +} from '~resources/utils' import Vue from 'vue' describeWithShallowAndMount('trigger', (mountingMethod) => { @@ -118,22 +122,24 @@ describeWithShallowAndMount('trigger', (mountingMethod) => { wrapper.trigger('keydown') }) - it('handles instances without update watchers', () => { - const vm = new Vue() - const item = () => vm.$createElement('button') - const TestComponent = { - render (h) { - return h(ComponentWithScopedSlots, { - scopedSlots: { - noProps: item - } - }) + itDoNotRunIf( + !scopedSlotsSupported(), + 'handles instances without update watchers', () => { + const vm = new Vue() + const item = () => vm.$createElement('button') + const TestComponent = { + render (h) { + return h(ComponentWithScopedSlots, { + scopedSlots: { + noProps: item + } + }) + } } - } - const wrapper = mountingMethod(TestComponent) + const wrapper = mountingMethod(TestComponent) - wrapper.findAll('button').trigger('click') - }) + wrapper.findAll('button').trigger('click') + }) it('throws error if options contains a target value', () => { const wrapper = mountingMethod({ render: (h) => h('div') }) From fed174efc8a1fd178e0e25855e55ed8f6891b1b1 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 5 May 2018 16:05:30 +0100 Subject: [PATCH 4/5] refactor: change test utils checks to consts --- test/resources/utils.js | 20 +++++-------------- test/specs/mount.spec.js | 2 +- test/specs/mounting-options/attrs.spec.js | 2 +- test/specs/mounting-options/listeners.spec.js | 2 +- test/specs/mounting-options/provide.spec.js | 14 ++++++------- test/specs/wrapper/contains.spec.js | 2 +- test/specs/wrapper/find.spec.js | 2 +- test/specs/wrapper/findAll.spec.js | 2 +- test/specs/wrapper/is.spec.js | 2 +- test/specs/wrapper/props.spec.js | 2 +- test/specs/wrapper/trigger.spec.js | 2 +- 11 files changed, 21 insertions(+), 31 deletions(-) diff --git a/test/resources/utils.js b/test/resources/utils.js index 961c51445..cdef7fd09 100644 --- a/test/resources/utils.js +++ b/test/resources/utils.js @@ -16,25 +16,15 @@ export const isRunningPhantomJS = navigator.userAgent.includes && navigator.userAgent.match(/PhantomJS/i) -export function injectSupported () { - return vueVersion > 2.2 -} +export const injectSupported = vueVersion > 2.2 -export function attrsSupported () { - return vueVersion > 2.2 -} +export const attrsSupported = vueVersion > 2.2 -export function listenersSupported () { - return vueVersion > 2.3 -} +export const listenersSupported = vueVersion > 2.3 -export function functionalSFCsSupported () { - return vueVersion >= 2.5 -} +export const functionalSFCsSupported = vueVersion > 2.4 -export function scopedSlotsSupported () { - return vueVersion >= 2.1 -} +export const scopedSlotsSupported = vueVersion > 2 const shallowAndMount = process.env.TEST_ENV === 'node' ? [] diff --git a/test/specs/mount.spec.js b/test/specs/mount.spec.js index 2ae15c4cb..24f40730d 100644 --- a/test/specs/mount.spec.js +++ b/test/specs/mount.spec.js @@ -145,7 +145,7 @@ describeIf(process.env.TEST_ENV !== 'node', 'prop': 'val' } }) - if (injectSupported()) { + if (injectSupported) { // provide is added by Vue, it's a function in Vue > 2.3 if (vueVersion > 2.3) { expect(typeof wrapper.vm.$options.provide).to.equal('function') diff --git a/test/specs/mounting-options/attrs.spec.js b/test/specs/mounting-options/attrs.spec.js index b9982c3ff..ba3a0d8da 100644 --- a/test/specs/mounting-options/attrs.spec.js +++ b/test/specs/mounting-options/attrs.spec.js @@ -10,7 +10,7 @@ describeWithMountingMethods('options.attrs', (mountingMethod) => { itSkipIf( mountingMethod.name === 'renderToString' || isRunningPhantomJS, 'handles inherit attrs', () => { - if (!attrsSupported()) return + if (!attrsSupported) return const wrapper = mountingMethod(compileToFunctions('

'), { attrs: { anAttr: 'an attribute' diff --git a/test/specs/mounting-options/listeners.spec.js b/test/specs/mounting-options/listeners.spec.js index 0f3364851..086127c7d 100644 --- a/test/specs/mounting-options/listeners.spec.js +++ b/test/specs/mounting-options/listeners.spec.js @@ -9,7 +9,7 @@ import { describeWithShallowAndMount('options.listeners', (mountingMethod) => { itSkipIf(isRunningPhantomJS, 'handles inherit listeners', () => { - if (!listenersSupported()) return + if (!listenersSupported) return const aListener = () => {} const wrapper = mountingMethod(compileToFunctions('

'), { listeners: { diff --git a/test/specs/mounting-options/provide.spec.js b/test/specs/mounting-options/provide.spec.js index a46432047..29fb8b785 100644 --- a/test/specs/mounting-options/provide.spec.js +++ b/test/specs/mounting-options/provide.spec.js @@ -19,9 +19,9 @@ describeWithMountingMethods('options.provide', (mountingMethod) => { config.provide = configProvideSave }) - itDoNotRunIf(!injectSupported(), + itDoNotRunIf(!injectSupported, 'provides objects which is injected by mounted component', () => { - if (!injectSupported()) return + if (!injectSupported) return const wrapper = mountingMethod(ComponentWithInject, { provide: { fromMount: 'objectValue' } @@ -32,7 +32,7 @@ describeWithMountingMethods('options.provide', (mountingMethod) => { expect(HTML).to.contain('objectValue') }) - itDoNotRunIf(!injectSupported(), + itDoNotRunIf(!injectSupported, 'provides function which is injected by mounted component', () => { const wrapper = mountingMethod(ComponentWithInject, { provide () { @@ -47,9 +47,9 @@ describeWithMountingMethods('options.provide', (mountingMethod) => { expect(HTML).to.contain('functionValue') }) - itDoNotRunIf(!injectSupported() || mountingMethod.name === 'renderToString', + itDoNotRunIf(!injectSupported || mountingMethod.name === 'renderToString', 'supports beforeCreate in component', () => { - if (!injectSupported()) return + if (!injectSupported) return const wrapper = mountingMethod(ComponentWithInject, { provide: { fromMount: '_' } @@ -60,7 +60,7 @@ describeWithMountingMethods('options.provide', (mountingMethod) => { itSkipIf(mountingMethod.name === 'renderToString', 'injects the provide from the config', () => { - if (!injectSupported()) { + if (!injectSupported) { return } config.provide['fromMount'] = 'globalConfig' @@ -73,7 +73,7 @@ describeWithMountingMethods('options.provide', (mountingMethod) => { expect(HTML).to.contain('globalConfig') }) - itDoNotRunIf(!injectSupported(), 'prioritize mounting options over config', () => { + itDoNotRunIf(!injectSupported, 'prioritize mounting options over config', () => { config.provide['fromMount'] = 'globalConfig' const wrapper = mountingMethod(ComponentWithInject, { diff --git a/test/specs/wrapper/contains.spec.js b/test/specs/wrapper/contains.spec.js index 9d292e1be..e0ac6f747 100644 --- a/test/specs/wrapper/contains.spec.js +++ b/test/specs/wrapper/contains.spec.js @@ -24,7 +24,7 @@ describeWithShallowAndMount('contains', (mountingMethod) => { }) it('returns true if wrapper contains functional Vue component', () => { - if (!functionalSFCsSupported()) { + if (!functionalSFCsSupported) { return false } const TestComponent = { diff --git a/test/specs/wrapper/find.spec.js b/test/specs/wrapper/find.spec.js index c4685d58e..d26cd6710 100644 --- a/test/specs/wrapper/find.spec.js +++ b/test/specs/wrapper/find.spec.js @@ -132,7 +132,7 @@ describeWithShallowAndMount('find', (mountingMethod) => { }) it('returns Wrapper of Vue Component matching functional component', () => { - if (!functionalSFCsSupported()) { + if (!functionalSFCsSupported) { return } const TestComponent = { diff --git a/test/specs/wrapper/findAll.spec.js b/test/specs/wrapper/findAll.spec.js index 78584cdc4..b207d6187 100644 --- a/test/specs/wrapper/findAll.spec.js +++ b/test/specs/wrapper/findAll.spec.js @@ -218,7 +218,7 @@ describeWithShallowAndMount('findAll', (mountingMethod) => { }) it('returns Wrapper of Vue Component matching functional component', () => { - if (!functionalSFCsSupported()) { + if (!functionalSFCsSupported) { return } const TestComponent = { diff --git a/test/specs/wrapper/is.spec.js b/test/specs/wrapper/is.spec.js index 95ae99b36..25a32ee3d 100644 --- a/test/specs/wrapper/is.spec.js +++ b/test/specs/wrapper/is.spec.js @@ -62,7 +62,7 @@ describeWithShallowAndMount('is', (mountingMethod) => { }) it('returns true if root node matches functional Component', () => { - if (!functionalSFCsSupported()) { + if (!functionalSFCsSupported) { return } const wrapper = mountingMethod(FunctionalComponent) diff --git a/test/specs/wrapper/props.spec.js b/test/specs/wrapper/props.spec.js index 53a399fc0..bce89ee19 100644 --- a/test/specs/wrapper/props.spec.js +++ b/test/specs/wrapper/props.spec.js @@ -36,7 +36,7 @@ describeWithShallowAndMount('props', (mountingMethod) => { expect(wrapper.props()).to.eql({ prop1: {}, prop2: 'val2' }) // fail }) - itSkipIf(!functionalSFCsSupported(), + itSkipIf(!functionalSFCsSupported, 'works correctly a functional component', () => { const FunctionalComponent = { render: h => h('div'), diff --git a/test/specs/wrapper/trigger.spec.js b/test/specs/wrapper/trigger.spec.js index 22c9d254d..4d6622730 100644 --- a/test/specs/wrapper/trigger.spec.js +++ b/test/specs/wrapper/trigger.spec.js @@ -123,7 +123,7 @@ describeWithShallowAndMount('trigger', (mountingMethod) => { }) itDoNotRunIf( - !scopedSlotsSupported(), + !scopedSlotsSupported, 'handles instances without update watchers', () => { const vm = new Vue() const item = () => vm.$createElement('button') From 406bbc3042888c7c29b7a9e244b0a99d30016303 Mon Sep 17 00:00:00 2001 From: Edd Yerburgh Date: Sat, 5 May 2018 18:31:45 +0100 Subject: [PATCH 5/5] Update utils.js --- test/resources/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/resources/utils.js b/test/resources/utils.js index cdef7fd09..548bf2fd9 100644 --- a/test/resources/utils.js +++ b/test/resources/utils.js @@ -20,7 +20,7 @@ export const injectSupported = vueVersion > 2.2 export const attrsSupported = vueVersion > 2.2 -export const listenersSupported = vueVersion > 2.3 +export const listenersSupported = vueVersion > 2.3 export const functionalSFCsSupported = vueVersion > 2.4