Skip to content

Commit

Permalink
feat(ng-dev): ComponentContext now disables animations from `provid…
Browse files Browse the repository at this point in the history
…eAnimations()`, not just `BrowserAnimationsModule`
  • Loading branch information
ersimont committed May 9, 2023
1 parent b734bc1 commit 9f0c650
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Expand Up @@ -13,6 +13,7 @@ import { BrowserModule, By } from '@angular/platform-browser';
import {
ANIMATION_MODULE_TYPE,
BrowserAnimationsModule,
provideAnimations,
} from '@angular/platform-browser/animations';
import { RouterModule, Routes } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
Expand Down Expand Up @@ -58,10 +59,9 @@ describe('ComponentContext', () => {
});

it('disables animations', () => {
@NgModule({ imports: [BrowserAnimationsModule] })
class AnimatedModule {}
// do not use NoopAnimationsModule, because its timing is less finicky
const ctx = new ComponentContext(TestComponent, {
imports: [AnimatedModule],
providers: [provideAnimations()],
});
ctx.run(() => {
expect(ctx.inject(ANIMATION_MODULE_TYPE)).toBe('NoopAnimations');
Expand Down
13 changes: 10 additions & 3 deletions projects/ng-dev/src/lib/component-context/component-context.ts
Expand Up @@ -10,7 +10,10 @@ import {
tick,
} from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import {
NoopAnimationsModule,
provideNoopAnimations,
} from '@angular/platform-browser/animations';
import { assert } from '@s-libs/js-core';
import { keys } from '@s-libs/micro-dash';
import {
Expand Down Expand Up @@ -172,10 +175,14 @@ export class ComponentContext<T> extends AngularContext {
const mirror = reflectComponentType(componentType);
assert(mirror, 'That does not appear to be a component');
const inputProperties = WrapperComponent.wrap(mirror, unboundInputs);
const imports: any[] = [NoopAnimationsModule];
const imports: any[] = [];
const declarations: any[] = [WrapperComponent];
(mirror.isStandalone ? imports : declarations).push(componentType);
super(extendMetadata(moduleMetadata, { imports, declarations }));
super(
extendMetadata({ imports, declarations }, moduleMetadata, {
providers: [provideNoopAnimations()],
}),
);

this.#componentType = componentType;
this.#inputProperties = new Set(inputProperties);
Expand Down

0 comments on commit 9f0c650

Please sign in to comment.