From 962b778e109807c2da34025c9ca8f6ba08c48bbe Mon Sep 17 00:00:00 2001 From: Phan An Date: Sat, 10 Dec 2016 01:51:13 +0800 Subject: [PATCH] More informative warning message for comp name (#4429) This commit adds a more informative warning message for invalid component names. Also fixes a typo. Closes #4428. --- src/core/global-api/extend.js | 3 ++- test/unit/features/options/name.spec.js | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/core/global-api/extend.js b/src/core/global-api/extend.js index e0027c30..c6cae8ec 100644 --- a/src/core/global-api/extend.js +++ b/src/core/global-api/extend.js @@ -28,7 +28,8 @@ export function initExtend (Vue: GlobalAPI) { if (!/^[a-zA-Z][\w-]*$/.test(name)) { warn( 'Invalid component name: "' + name + '". Component names ' + - 'can only contain alphanumeric characaters and the hyphen.' + 'can only contain alphanumeric characters and the hyphen, ' + + 'and must start with a letter.' ) } } diff --git a/test/unit/features/options/name.spec.js b/test/unit/features/options/name.spec.js index 74cccd00..2f586f85 100644 --- a/test/unit/features/options/name.spec.js +++ b/test/unit/features/options/name.spec.js @@ -15,7 +15,16 @@ describe('Options name', () => { }) /* eslint-disable */ - expect(`Invalid component name: "Hyper*Vue". Component names can only contain alphanumeric characaters and the hyphen.`) + expect(`Invalid component name: "Hyper*Vue". Component names can only contain alphanumeric characters and the hyphen, and must start with a letter.`) + .toHaveBeenWarned() + /* eslint-enable */ + + Vue.extend({ + name: '2Cool2BValid' + }) + + /* eslint-disable */ + expect(`Invalid component name: "2Cool2BValid". Component names can only contain alphanumeric characters and the hyphen, and must start with a letter.`) .toHaveBeenWarned() /* eslint-enable */ })