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

Open
wants to merge 1 commit into
base: beta
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions apps/example-app/src/test-setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone';
import { configure } from '@testing-library/angular';
import '@testing-library/jest-dom';

setupZoneTestEnv();
configure({
defaultImports: [NoopAnimationsModule],
});
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
Loading