Skip to content

Commit

Permalink
fix: handle cloneDeep errors in createLocalVue (#844)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyerburgh authored Jul 22, 2018
1 parent ef01abf commit 17dfdc8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/test-utils/src/create-local-vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ function createLocalVue (_Vue: Component = Vue): Component {
Object.keys(_Vue).forEach(key => {
if (!instance.hasOwnProperty(key)) {
const original = _Vue[key]
instance[key] =
typeof original === 'object' ? cloneDeep(original) : original
// cloneDeep can fail when cloning Vue instances
// cloneDeep checks that the instance has a Symbol
// which errors in Vue < 2.17 (https://github.com/vuejs/vue/pull/7878)
try {
instance[key] = typeof original === 'object'
? cloneDeep(original)
: original
} catch (e) {
instance[key] = original
}
}
})

Expand Down
10 changes: 10 additions & 0 deletions test/specs/mounting-options/localVue.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,14 @@ describeWithMountingMethods('options.localVue', mountingMethod => {
})
expect(localVue.options.created).to.equal(undefined)
})

it('handles merging Vue instances', () => {
const localVue = createLocalVue()
localVue.use((_Vue) => {
_Vue.$el = new _Vue()
})
mountingMethod({ template: '<div />' }, {
localVue
})
})
})

0 comments on commit 17dfdc8

Please sign in to comment.