Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular: how to fix Error: NG03600: Angular detected that the `AnimationBuilder` was injected, but animation support was not enabled

When I ran Angular unit test I got the following error many times:

Error: NG03600: Angular detected that the AnimationBuilder was injected, but animation support was not enabled. Please make sure that you enable animations in your application by calling provideAnimations() or provideAnimationsAsync() function.

What can be the cause of that, how can I fix that?

like image 689
Laszlo Avatar asked Oct 20 '25 11:10

Laszlo


1 Answers

Try importing provideAnimations or provideAnimationsAsync on providers array.

Since the component under testing is using animations, angular depends on animations module as the error states.

  TestBed.configureTestingModule({
    // provide the component-under-test and dependent service
    providers: [
      ...
      provideAnimations(),
      ...
    ]
  });

For setting it globally, you can simply use a wrapper function that add this dynamically.

export const setConfigWrapper = (baseObject: any) => {
    if(baseObject?.providers?.length) {
        baseObject.providers.push(provideAnimations());
    } else {
        baseObject.providers = [provideAnimations()];
    }
    return baseObject;
}

Then you can use it like so.

  TestBed.configureTestingModule(setConfigWrapper({
    // provide the component-under-test and dependent service
    providers: [
      ...
      ...
    ]
  }));
like image 197
Naren Murali Avatar answered Oct 22 '25 02:10

Naren Murali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!