Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: only order deps if watcher exists #583

Merged
merged 4 commits into from
May 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/server-test-utils/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ rollupOptions.forEach(options => {
.then(() => success(`${options.format} build successful`))
.catch((err) => {
error(err)
process.exit(1)
})
})
1 change: 1 addition & 0 deletions packages/test-utils/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@ rollupOptions.forEach(options => {
.then(() => success(`${options.format} build successful`))
.catch((err) => {
error(err)
process.exit(1)
})
})
2 changes: 1 addition & 1 deletion packages/test-utils/src/order-watchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function orderVmWatchers (vm) {
})
}

orderDeps(vm._watcher)
vm._watcher && orderDeps(vm._watcher)

vm.$children.forEach(orderVmWatchers)
}
Expand Down
18 changes: 6 additions & 12 deletions test/resources/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +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 const scopedSlotsSupported = vueVersion > 2

const shallowAndMount = process.env.TEST_ENV === 'node'
? []
Expand Down
2 changes: 1 addition & 1 deletion test/specs/mount.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion test/specs/mounting-options/attrs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<p :id="anAttr" />'), {
attrs: {
anAttr: 'an attribute'
Expand Down
2 changes: 1 addition & 1 deletion test/specs/mounting-options/listeners.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<p :id="aListener" />'), {
listeners: {
Expand Down
14 changes: 7 additions & 7 deletions test/specs/mounting-options/provide.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand All @@ -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 () {
Expand All @@ -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: '_' }
Expand All @@ -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'
Expand All @@ -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, {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/wrapper/contains.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describeWithShallowAndMount('contains', (mountingMethod) => {
})

it('returns true if wrapper contains functional Vue component', () => {
if (!functionalSFCsSupported()) {
if (!functionalSFCsSupported) {
return false
}
const TestComponent = {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/wrapper/find.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describeWithShallowAndMount('find', (mountingMethod) => {
})

it('returns Wrapper of Vue Component matching functional component', () => {
if (!functionalSFCsSupported()) {
if (!functionalSFCsSupported) {
return
}
const TestComponent = {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/wrapper/findAll.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ describeWithShallowAndMount('findAll', (mountingMethod) => {
})

it('returns Wrapper of Vue Component matching functional component', () => {
if (!functionalSFCsSupported()) {
if (!functionalSFCsSupported) {
return
}
const TestComponent = {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/wrapper/is.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/specs/wrapper/props.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
27 changes: 26 additions & 1 deletion test/specs/wrapper/trigger.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import ComponentWithEvents from '~resources/components/component-with-events.vue'
import { describeWithShallowAndMount } from '~resources/utils'
import ComponentWithScopedSlots from '~resources/components/component-with-scoped-slots.vue'
import {
describeWithShallowAndMount,
itDoNotRunIf,
scopedSlotsSupported
} from '~resources/utils'
import Vue from 'vue'

describeWithShallowAndMount('trigger', (mountingMethod) => {
let info
Expand Down Expand Up @@ -116,6 +122,25 @@ describeWithShallowAndMount('trigger', (mountingMethod) => {
wrapper.trigger('keydown')
})

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)

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')
Expand Down