Skip to content

feat: remove animations dependency #531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions apps/example-app/src/app/examples/15-dialog.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { MatDialogRef } from '@angular/material/dialog';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { render, screen } from '@testing-library/angular';
import userEvent from '@testing-library/user-event';

Expand All @@ -9,6 +10,7 @@ test('dialog closes', async () => {

const closeFn = jest.fn();
await render(DialogContentComponent, {
imports: [NoopAnimationsModule],
providers: [
{
provide: MatDialogRef,
Expand All @@ -28,7 +30,9 @@ test('dialog closes', async () => {
test('closes the dialog via the backdrop', async () => {
const user = userEvent.setup();

await render(DialogComponent);
await render(DialogComponent, {
imports: [NoopAnimationsModule],
});

const openDialogButton = await screen.findByRole('button', { name: /open dialog/i });
await user.click(openDialogButton);
Expand All @@ -50,7 +54,9 @@ test('closes the dialog via the backdrop', async () => {
test('opens and closes the dialog with buttons', async () => {
const user = userEvent.setup();

await render(DialogComponent);
await render(DialogComponent, {
imports: [NoopAnimationsModule],
});

const openDialogButton = await screen.findByRole('button', { name: /open dialog/i });
await user.click(openDialogButton);
Expand Down
1 change: 0 additions & 1 deletion projects/testing-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"migrations": "./schematics/migrations/migrations.json"
},
"peerDependencies": {
"@angular/animations": ">= 20.0.0",
"@angular/common": ">= 20.0.0",
"@angular/platform-browser": ">= 20.0.0",
"@angular/router": ">= 20.0.0",
Expand Down
3 changes: 1 addition & 2 deletions projects/testing-library/src/lib/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,11 @@ export interface RenderComponentOptions<ComponentType, Q extends Queries = typeo
/**
* @description
* A collection of imports needed to render the component, for example, shared modules.
* Adds `NoopAnimationsModule` by default if `BrowserAnimationsModule` isn't added to the collection.
*
* For more info see https://angular.io/api/core/NgModule#imports
*
* @default
* `[NoopAnimationsModule]`
* `[]`
*
* @example
* await render(AppComponent, {
Expand Down
9 changes: 1 addition & 8 deletions projects/testing-library/src/lib/testing-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
isStandalone,
} from '@angular/core';
import { ComponentFixture, DeferBlockBehavior, DeferBlockState, TestBed, tick } from '@angular/core/testing';
import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform-browser/animations';
import { NavigationExtras, Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import type { BoundFunctions, Queries } from '@testing-library/dom';
Expand Down Expand Up @@ -513,15 +512,9 @@ function addAutoImports<SutType>(
sut: Type<SutType> | string,
{ imports = [], routes }: Pick<RenderComponentOptions<any>, 'imports' | 'routes'>,
) {
const animations = () => {
const animationIsDefined =
imports.indexOf(NoopAnimationsModule) > -1 || imports.indexOf(BrowserAnimationsModule) > -1;
return animationIsDefined ? [] : [NoopAnimationsModule];
};

const routing = () => (routes ? [RouterTestingModule.withRoutes(routes)] : []);
const components = () => (typeof sut !== 'string' && isStandalone(sut) ? [sut] : []);
return [...imports, ...components(), ...animations(), ...routing()];
return [...imports, ...components(), ...routing()];
}

async function renderDeferBlock<SutType>(
Expand Down
20 changes: 0 additions & 20 deletions projects/testing-library/tests/render.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
model,
} from '@angular/core';
import { outputFromObservable } from '@angular/core/rxjs-interop';
import { NoopAnimationsModule, BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { TestBed } from '@angular/core/testing';
import { render, fireEvent, screen, OutputRefKeysWithCallback, aliasedInput } from '../src/public_api';
import { ActivatedRoute, Resolve, RouterModule } from '@angular/router';
Expand Down Expand Up @@ -331,25 +330,6 @@ describe('excludeComponentDeclaration', () => {
});
});

describe('animationModule', () => {
it('adds NoopAnimationsModule by default', async () => {
await render(FixtureComponent);
const noopAnimationsModule = TestBed.inject(NoopAnimationsModule);
expect(noopAnimationsModule).toBeDefined();
});

it('does not add NoopAnimationsModule if BrowserAnimationsModule is an import', async () => {
await render(FixtureComponent, {
imports: [BrowserAnimationsModule],
});

const browserAnimationsModule = TestBed.inject(BrowserAnimationsModule);
expect(browserAnimationsModule).toBeDefined();

expect(() => TestBed.inject(NoopAnimationsModule)).toThrow();
});
});

describe('Angular component life-cycle hooks', () => {
@Component({
selector: 'atl-fixture',
Expand Down