When running Karma to test my Angular4 application, I get this error Found the synthetic property @enterAnimation. Please include either \"BrowserAnimationsModule\" o
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,
...
],
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';
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,
],
})
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!
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();
}));
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";