From 17dfdc80cbbbf9a4d8cbc39997101ae413ce1db5 Mon Sep 17 00:00:00 2001 From: Edd Yerburgh Date: Sun, 22 Jul 2018 09:20:30 +0100 Subject: [PATCH] fix: handle cloneDeep errors in createLocalVue (#844) --- packages/test-utils/src/create-local-vue.js | 12 ++++++++++-- test/specs/mounting-options/localVue.spec.js | 10 ++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/test-utils/src/create-local-vue.js b/packages/test-utils/src/create-local-vue.js index 2a0979c71..1732997dd 100644 --- a/packages/test-utils/src/create-local-vue.js +++ b/packages/test-utils/src/create-local-vue.js @@ -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 + } } }) diff --git a/test/specs/mounting-options/localVue.spec.js b/test/specs/mounting-options/localVue.spec.js index a64011d1a..6be3aa283 100644 --- a/test/specs/mounting-options/localVue.spec.js +++ b/test/specs/mounting-options/localVue.spec.js @@ -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: '
' }, { + localVue + }) + }) })