@@ -23,7 +23,7 @@ describe('Component Schematic', () => {
2323 inlineStyle : false ,
2424 inlineTemplate : false ,
2525 displayBlock : false ,
26- changeDetection : ChangeDetection . Eager ,
26+ changeDetection : ChangeDetection . OnPush ,
2727 style : Style . Css ,
2828 type : 'Component' ,
2929 skipTests : false ,
@@ -64,12 +64,23 @@ describe('Component Schematic', () => {
6464 expect ( tsContent ) . toContain ( 'compileComponents()' ) ;
6565 } ) ;
6666
67- it ( 'should set change detection to OnPush' , async ( ) => {
68- const options = { ...defaultOptions , changeDetection : 'OnPush' } ;
67+ it ( 'should not set change detection when default is OnPush' , async ( ) => {
68+ const options = { ...defaultOptions } ;
69+
70+ const tree = await schematicRunner . runSchematic ( 'component' , options , appTree ) ;
71+ const tsContent = tree . readContent ( '/projects/bar/src/app/foo/foo.component.ts' ) ;
72+ expect ( tsContent ) . not . toMatch ( / i m p o r t .* C h a n g e D e t e c t i o n S t r a t e g y / ) ;
73+ expect ( tsContent ) . not . toMatch ( / c h a n g e D e t e c t i o n : / ) ;
74+ expect ( tsContent ) . not . toMatch ( / C h a n g e D e t e c t i o n S t r a t e g y / ) ;
75+ } ) ;
76+
77+ it ( 'should set changeDetection to Eager when requested' , async ( ) => {
78+ const options = { ...defaultOptions , changeDetection : 'Eager' } ;
6979
7080 const tree = await schematicRunner . runSchematic ( 'component' , options , appTree ) ;
7181 const tsContent = tree . readContent ( '/projects/bar/src/app/foo/foo.component.ts' ) ;
72- expect ( tsContent ) . toMatch ( / c h a n g e D e t e c t i o n : C h a n g e D e t e c t i o n S t r a t e g y .O n P u s h / ) ;
82+ expect ( tsContent ) . toMatch ( / i m p o r t .* C h a n g e D e t e c t i o n S t r a t e g y / ) ;
83+ expect ( tsContent ) . toContain ( 'changeDetection: ChangeDetectionStrategy.Eager,' ) ;
7384 } ) ;
7485
7586 it ( 'should not set view encapsulation' , async ( ) => {
@@ -348,27 +359,27 @@ describe('Component Schematic', () => {
348359 expect ( tree . files ) . not . toContain ( '/projects/bar/src/app/foo/foo.component.spec.ts' ) ;
349360 } ) ;
350361
351- it ( 'should respect templateUrl when style=none and changeDetection=OnPush ' , async ( ) => {
352- const options = { ...defaultOptions , style : Style . None , changeDetection : 'OnPush ' } ;
362+ it ( 'should respect templateUrl when style=none and changeDetection=Eager ' , async ( ) => {
363+ const options = { ...defaultOptions , style : Style . None , changeDetection : 'Eager ' } ;
353364 const tree = await schematicRunner . runSchematic ( 'component' , options , appTree ) ;
354365 const content = tree . readContent ( '/projects/bar/src/app/foo/foo.component.ts' ) ;
355366 expect ( content ) . not . toMatch ( / s t y l e U r l s : / ) ;
356367 expect ( content ) . toMatch ( / t e m p l a t e U r l : ' .\/ f o o .c o m p o n e n t .h t m l ' , \n / ) ;
357- expect ( content ) . toMatch ( / c h a n g e D e t e c t i o n : C h a n g e D e t e c t i o n S t r a t e g y .O n P u s h / ) ;
368+ expect ( content ) . toMatch ( / c h a n g e D e t e c t i o n : C h a n g e D e t e c t i o n S t r a t e g y .E a g e r / ) ;
358369 } ) ;
359370
360- it ( 'should respect inlineTemplate when style=none and changeDetection=OnPush ' , async ( ) => {
371+ it ( 'should respect inlineTemplate when style=none and changeDetection=Eager ' , async ( ) => {
361372 const options = {
362373 ...defaultOptions ,
363374 style : Style . None ,
364- changeDetection : 'OnPush ' ,
375+ changeDetection : 'Eager ' ,
365376 inlineTemplate : true ,
366377 } ;
367378 const tree = await schematicRunner . runSchematic ( 'component' , options , appTree ) ;
368379 const content = tree . readContent ( '/projects/bar/src/app/foo/foo.component.ts' ) ;
369380 expect ( content ) . not . toMatch ( / s t y l e U r l s : / ) ;
370381 expect ( content ) . toMatch ( / t e m p l a t e : ` ( \n ( .| ) * ) { 3 } \n \s * ` , \n / ) ;
371- expect ( content ) . toMatch ( / c h a n g e D e t e c t i o n : C h a n g e D e t e c t i o n S t r a t e g y .O n P u s h / ) ;
382+ expect ( content ) . toMatch ( / c h a n g e D e t e c t i o n : C h a n g e D e t e c t i o n S t r a t e g y .E a g e r , / ) ;
372383 } ) ;
373384
374385 it ( 'should create a standalone component' , async ( ) => {
0 commit comments