Skip to content

Commit 8ddb0cc

Browse files
committed
feat: remove animations dependency
BREAKING CHANGE Because of the removal of the animations dependency, the NoopAnimationsModule is no longer automatically imported in the render. BEFORE: The NoopAnimationsModule was always imported to the render. AFTER: Import the NoopAnimationsModule where needed, or configure the default imports using configure: ` s configure({ defaultImports: [NoopAnimationsModule], }); `
1 parent 6a64bbe commit 8ddb0cc

File tree

5 files changed

+7
-31
lines changed

5 files changed

+7
-31
lines changed

apps/example-app/src/test-setup.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
12
import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone';
3+
import { configure } from '@testing-library/angular';
24
import '@testing-library/jest-dom';
35

46
setupZoneTestEnv();
7+
configure({
8+
defaultImports: [NoopAnimationsModule],
9+
});

projects/testing-library/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"migrations": "./schematics/migrations/migrations.json"
3030
},
3131
"peerDependencies": {
32-
"@angular/animations": ">= 20.0.0",
3332
"@angular/common": ">= 20.0.0",
3433
"@angular/platform-browser": ">= 20.0.0",
3534
"@angular/router": ">= 20.0.0",

projects/testing-library/src/lib/models.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,11 @@ export interface RenderComponentOptions<ComponentType, Q extends Queries = typeo
178178
/**
179179
* @description
180180
* A collection of imports needed to render the component, for example, shared modules.
181-
* Adds `NoopAnimationsModule` by default if `BrowserAnimationsModule` isn't added to the collection.
182181
*
183182
* For more info see https://angular.io/api/core/NgModule#imports
184183
*
185184
* @default
186-
* `[NoopAnimationsModule]`
185+
* `[]`
187186
*
188187
* @example
189188
* await render(AppComponent, {

projects/testing-library/src/lib/testing-library.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
isStandalone,
1313
} from '@angular/core';
1414
import { ComponentFixture, DeferBlockBehavior, DeferBlockState, TestBed, tick } from '@angular/core/testing';
15-
import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform-browser/animations';
1615
import { NavigationExtras, Router } from '@angular/router';
1716
import { RouterTestingModule } from '@angular/router/testing';
1817
import type { BoundFunctions, Queries } from '@testing-library/dom';
@@ -513,15 +512,9 @@ function addAutoImports<SutType>(
513512
sut: Type<SutType> | string,
514513
{ imports = [], routes }: Pick<RenderComponentOptions<any>, 'imports' | 'routes'>,
515514
) {
516-
const animations = () => {
517-
const animationIsDefined =
518-
imports.indexOf(NoopAnimationsModule) > -1 || imports.indexOf(BrowserAnimationsModule) > -1;
519-
return animationIsDefined ? [] : [NoopAnimationsModule];
520-
};
521-
522515
const routing = () => (routes ? [RouterTestingModule.withRoutes(routes)] : []);
523516
const components = () => (typeof sut !== 'string' && isStandalone(sut) ? [sut] : []);
524-
return [...imports, ...components(), ...animations(), ...routing()];
517+
return [...imports, ...components(), ...routing()];
525518
}
526519

527520
async function renderDeferBlock<SutType>(

projects/testing-library/tests/render.spec.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
model,
1818
} from '@angular/core';
1919
import { outputFromObservable } from '@angular/core/rxjs-interop';
20-
import { NoopAnimationsModule, BrowserAnimationsModule } from '@angular/platform-browser/animations';
2120
import { TestBed } from '@angular/core/testing';
2221
import { render, fireEvent, screen, OutputRefKeysWithCallback, aliasedInput } from '../src/public_api';
2322
import { ActivatedRoute, Resolve, RouterModule } from '@angular/router';
@@ -331,25 +330,6 @@ describe('excludeComponentDeclaration', () => {
331330
});
332331
});
333332

334-
describe('animationModule', () => {
335-
it('adds NoopAnimationsModule by default', async () => {
336-
await render(FixtureComponent);
337-
const noopAnimationsModule = TestBed.inject(NoopAnimationsModule);
338-
expect(noopAnimationsModule).toBeDefined();
339-
});
340-
341-
it('does not add NoopAnimationsModule if BrowserAnimationsModule is an import', async () => {
342-
await render(FixtureComponent, {
343-
imports: [BrowserAnimationsModule],
344-
});
345-
346-
const browserAnimationsModule = TestBed.inject(BrowserAnimationsModule);
347-
expect(browserAnimationsModule).toBeDefined();
348-
349-
expect(() => TestBed.inject(NoopAnimationsModule)).toThrow();
350-
});
351-
});
352-
353333
describe('Angular component life-cycle hooks', () => {
354334
@Component({
355335
selector: 'atl-fixture',

0 commit comments

Comments
 (0)