Found the synthetic property @enterAnimation. Please include either “BrowserAnimationsModule” or “NoopAnimationsModule” in your application. Angular4

后端 未结 8 1337
生来不讨喜
生来不讨喜 2020-12-30 18:21

When running Karma to test my Angular4 application, I get this error Found the synthetic property @enterAnimation. Please include either \"BrowserAnimationsModule\" o

相关标签:
8条回答
  • 2020-12-30 18:39

    I found the solution. I just needed to import in app.component.spec.ts the same import

     // animation module
            import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 
        ...
    @NgModule({
        imports: [...
            BrowserAnimationsModule,
            ...
          ],
    
    0 讨论(0)
  • 2020-12-30 18:40

    If you see this error during unit testing then you could import utility module like NoopAnimationsModule into your spec file which mocks the real animation and donot actually animate

    import { NoopAnimationsModule } from '@angular/platform-browser/animations';

    0 讨论(0)
  • 2020-12-30 18:41

    for my case all i did was add this line to my component (users-component.ts)

    @Component({
    animations: [appModuleAnimation()],
    })
    

    of course ensure you have imported the relevant module in app.component.ts or where you import your modules

     // animation module
        import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 
    
        @NgModule({
             imports: [
                BrowserAnimationsModule,
            ],
        })
    
    0 讨论(0)
  • 2020-12-30 18:44

    If you face this error in Storybook, then do import this BrowserAnimationsModule to moduleMetadata in your story.
    Like this,

    import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
    
    
    export const Primary = () => ({
      template: `
       <div style="width: 720px">
        <view-list [data]="data"></view-list>
       </div>
       `,
      moduleMetadata: {
        imports: [AppModule, BrowserAnimationsModule],
      },
      props: {
        data: SOME_DATA_CONSTANT,
      },
    });
    

    PS: For Angular, answers that are mentioned above works well!

    0 讨论(0)
  • 2020-12-30 18:48

    For my Angular 6 application, I resolved the issue by adding the following to my component .spec.ts file:

    import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
    

    Then add the BrowserAnimationsModule to the imports of the TestBed.configureTestingModule in the same component .spec.ts file

      beforeEach(async(() => {
        TestBed.configureTestingModule({
          declarations: [ LinkedSitesComponent ], imports: [ BrowserAnimationsModule ],
        })
        .compileComponents();
      }));
    
    0 讨论(0)
  • 2020-12-30 18:48

    For angular 7 and previous version, you only need to add this line in your app.module.ts file, and remember put it in the imports array modules too in the same file:

    import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
    
    0 讨论(0)
提交回复
热议问题