File tree Expand file tree Collapse file tree 4 files changed +20
-2
lines changed
packages/schematics/angular Expand file tree Collapse file tree 4 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ import {
2525import { addDeclarationToNgModule } from '../utility/add-declaration-to-ng-module' ;
2626import { findModuleFromOptions } from '../utility/find-module' ;
2727import { parseName } from '../utility/parse-name' ;
28- import { validateHtmlSelector } from '../utility/validation' ;
28+ import { validateClassName , validateHtmlSelector } from '../utility/validation' ;
2929import { buildDefaultPath , getWorkspace } from '../utility/workspace' ;
3030import { Schema as ComponentOptions , Style } from './schema' ;
3131
@@ -62,6 +62,7 @@ export default function (options: ComponentOptions): Rule {
6262 options . selector || buildSelector ( options , ( project && project . prefix ) || '' ) ;
6363
6464 validateHtmlSelector ( options . selector ) ;
65+ validateClassName ( strings . classify ( options . name ) ) ;
6566
6667 const skipStyleFile = options . inlineStyle || options . style === Style . None ;
6768 const templateSource = apply ( url ( './files' ) , [
Original file line number Diff line number Diff line change @@ -157,6 +157,14 @@ describe('Component Schematic', () => {
157157 ) . toBeRejectedWithError ( 'Selector "app-1-one" is invalid.' ) ;
158158 } ) ;
159159
160+ it ( 'should error when class name contains invalid characters' , async ( ) => {
161+ const options = { ...defaultOptions , name : '404' } ;
162+
163+ await expectAsync (
164+ schematicRunner . runSchematic ( 'component' , options , appTree ) ,
165+ ) . toBeRejectedWithError ( 'Class name "404" is invalid.' ) ;
166+ } ) ;
167+
160168 it ( 'should allow dash in selector before a number' , async ( ) => {
161169 const options = { ...defaultOptions , name : 'one-1' } ;
162170
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ import {
2323import { addDeclarationToNgModule } from '../utility/add-declaration-to-ng-module' ;
2424import { findModuleFromOptions } from '../utility/find-module' ;
2525import { parseName } from '../utility/parse-name' ;
26- import { validateHtmlSelector } from '../utility/validation' ;
26+ import { validateClassName , validateHtmlSelector } from '../utility/validation' ;
2727import { buildDefaultPath , getWorkspace } from '../utility/workspace' ;
2828import { Schema as DirectiveOptions } from './schema' ;
2929
@@ -58,6 +58,7 @@ export default function (options: DirectiveOptions): Rule {
5858 options . selector = options . selector || buildSelector ( options , project . prefix || '' ) ;
5959
6060 validateHtmlSelector ( options . selector ) ;
61+ validateClassName ( strings . classify ( options . name ) ) ;
6162
6263 const templateSource = apply ( url ( './files' ) , [
6364 options . skipTests ? filter ( ( path ) => ! path . endsWith ( '.spec.ts.template' ) ) : noop ( ) ,
Original file line number Diff line number Diff line change @@ -111,6 +111,14 @@ describe('Directive Schematic', () => {
111111 expect ( directiveContent ) . toContain ( 'class FooDirective' ) ;
112112 } ) ;
113113
114+ it ( 'should error when class name contains invalid characters' , async ( ) => {
115+ const options = { ...defaultOptions , name : '404' } ;
116+
117+ await expectAsync (
118+ schematicRunner . runSchematic ( 'component' , options , appTree ) ,
119+ ) . toBeRejectedWithError ( 'Class name "404" is invalid.' ) ;
120+ } ) ;
121+
114122 describe ( 'standalone=false' , ( ) => {
115123 const defaultNonStandaloneOptions : DirectiveOptions = {
116124 ...defaultOptions ,
You can’t perform that action at this time.
0 commit comments