@@ -27,7 +27,19 @@ describe('ng-add schematic', () => {
2727 `Expected "${ filePath } " to be added to the project styles in the workspace.` ) ;
2828 }
2929
30+ /** Removes the specified dependency from the /package.json in the given tree. */
31+ function removePackageJsonDependency ( tree : Tree , dependencyName : string ) {
32+ const packageContent = JSON . parse ( getFileContent ( tree , '/package.json' ) ) ;
33+ delete packageContent . dependencies [ dependencyName ] ;
34+ tree . overwrite ( '/package.json' , JSON . stringify ( packageContent , null , 2 ) ) ;
35+ }
36+
3037 it ( 'should update package.json' , ( ) => {
38+ // By default, the Angular workspace schematic sets up "@angular/animations". In order
39+ // to verify that we would set up the dependency properly if someone doesn't have the
40+ // animations installed already, we remove the animations dependency explicitly.
41+ removePackageJsonDependency ( appTree , '@angular/animations' ) ;
42+
3143 const tree = runner . runSchematic ( 'ng-add' , { } , appTree ) ;
3244 const packageJson = JSON . parse ( getFileContent ( tree , '/package.json' ) ) ;
3345 const dependencies = packageJson . dependencies ;
@@ -142,4 +154,28 @@ describe('ng-add schematic', () => {
142154 'Expected the project main file to not contain a HammerJS import.' ) ;
143155 } ) ;
144156 } ) ;
157+
158+ describe ( 'animations disabled' , ( ) => {
159+
160+ it ( 'should not add @angular/animations to package.json' , ( ) => {
161+ // By default, the Angular workspace schematic sets up "@angular/animations". In order
162+ // to verify that we don't add the animations if the Animations are not installed, we need
163+ // to remove the dependency for this unit test tree.
164+ removePackageJsonDependency ( appTree , '@angular/animations' ) ;
165+
166+ const tree = runner . runSchematic ( 'ng-add' , { animations : false } , appTree ) ;
167+ const packageJson = JSON . parse ( getFileContent ( tree , '/package.json' ) ) ;
168+
169+ expect ( packageJson . dependencies [ '@angular/animations' ] )
170+ . toBeUndefined ( `Expected '@angular/animations' to be not added to the package.json` ) ;
171+ } ) ;
172+
173+ it ( 'should not add the BrowserAnimationsModule to the project module' , ( ) => {
174+ const tree = runner . runSchematic ( 'ng-add' , { gestures : false } , appTree ) ;
175+ const fileContent = getFileContent ( tree , '/projects/material/src/app/app.module.ts' ) ;
176+
177+ expect ( fileContent ) . not . toContain ( 'BrowserAnimationsModule' ,
178+ 'Expected the project app module to not import the "BrowserAnimationsModule".' ) ;
179+ } ) ;
180+ } ) ;
145181} ) ;
0 commit comments