Просмотр исходного кода

fix name warning when instantiating extended components (fix #3472)

Evan You 9 лет назад
Родитель
Сommit
6bdb577d4a
2 измененных файлов с 6 добавлено и 6 удалено
  1. 1 1
      src/core/util/options.js
  2. 5 5
      test/unit/features/options/name.spec.js

+ 1 - 1
src/core/util/options.js

@@ -36,7 +36,7 @@ if (process.env.NODE_ENV !== 'production') {
   }
 
   strats.name = function (parent, child, vm) {
-    if (vm) {
+    if (vm && child) {
       warn(
         'options "name" can only be used as a component definition option, ' +
         'not during instance creation.'

+ 5 - 5
test/unit/features/options/name.spec.js

@@ -2,14 +2,14 @@ import Vue from 'vue'
 
 describe('Options name', () => {
   it('should warn when giving instance a name', () => {
+    const Comp = Vue.component('custom', { name: 'custom' })
+    new Comp()
+    expect(`options "name" can only be used as a component definition option`).not.toHaveBeenWarned()
+
     new Vue({
       name: 'SuperVue'
     }).$mount()
-
-    /* eslint-disable */
-    expect(`options "name" can only be used as a component definition option, not during instance creation.`)
-      .toHaveBeenWarned()
-    /* eslint-enable */
+    expect(`options "name" can only be used as a component definition option`).toHaveBeenWarned()
   })
 
   it('should contain itself in self components', () => {