refactor(core): Update tests for zoneless by default (#63668)

This updates tests and examples only to prepare for zoneless by default.

These changes were identified and made as part of #63382. Anything that
failed gets `provideZoneChangeDetection` unless the fixes were easily
and quickly determined.

It also adds the zoneless provider to the `initTestEnvironment` calls
for tests in this repo to prevent regressions before #63382 is merged.

PR Close #63668
This commit is contained in:
Andrew Scott
2025-09-09 14:41:56 -07:00
parent 0571b335b9
commit c3576506b3
113 changed files with 908 additions and 205 deletions
@@ -13,6 +13,7 @@ import SpyObj = jasmine.SpyObj;
import {FrameManager} from '../../application-services/frame_manager';
import {Events, MessageBus} from '../../../../../protocol';
import {ApplicationOperations} from '../../application-operations';
import {provideZoneChangeDetection} from '@angular/core';
describe('RouterTreeComponent', () => {
let messageBus: MessageBus<Events>;
@@ -32,6 +33,7 @@ describe('RouterTreeComponent', () => {
await TestBed.configureTestingModule({
imports: [RouterTreeComponent],
providers: [
provideZoneChangeDetection(),
{provide: ApplicationOperations, useValue: applicationOperationsSpy},
{provide: MessageBus, useValue: messageBus},
{provide: FrameManager, useValue: frameManager},
@@ -11,6 +11,7 @@ describe('greet component', () => {
expect(fixture.nativeElement.textContent).toBe('Initial - initial-unset');
fixture.componentInstance.firstName = 'John';
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement.textContent).toBe('John - initial-unset');
+2 -1
View File
@@ -1,7 +1,8 @@
import {provideZoneChangeDetection} from '@angular/core';
import {bootstrapApplication, provideProtractorTestingSupport} from '@angular/platform-browser';
import {AppComponent} from './app/app.component';
bootstrapApplication(AppComponent, {
providers: [provideProtractorTestingSupport()],
providers: [provideZoneChangeDetection(), provideProtractorTestingSupport()],
});
@@ -1,4 +1,4 @@
import {NgModule} from '@angular/core';
import {NgModule, provideZoneChangeDetection} from '@angular/core';
import {
BrowserModule,
provideClientHydration,
@@ -11,7 +11,7 @@ import {AppComponent} from './app.component';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, AppRoutingModule],
providers: [provideClientHydration(withIncrementalHydration())],
providers: [provideZoneChangeDetection(), provideClientHydration(withIncrementalHydration())],
bootstrap: [AppComponent],
})
export class AppModule {}
@@ -4,9 +4,11 @@ import {provideClientHydration, withIncrementalHydration} from '@angular/platfor
import {provideRouter} from '@angular/router';
import {routes} from './app.routes';
import {provideZoneChangeDetection} from '@angular/core';
export const appConfig: ApplicationConfig = {
providers: [
provideZoneChangeDetection(),
provideRouter(routes),
provideClientHydration(withIncrementalHydration()),
provideHttpClient(),
@@ -13,6 +13,7 @@ import {
Component,
Input,
NgModule,
provideZoneChangeDetection,
TemplateRef,
ViewChild,
} from '@angular/core';
@@ -67,6 +68,7 @@ export class DeclarationComponent {
@NgModule({
declarations: [DeclarationComponent, InsertionComponent],
bootstrap: [DeclarationComponent],
providers: [provideZoneChangeDetection()],
imports: [BrowserModule],
})
export class TransplantedViewsModule {}
@@ -11,9 +11,10 @@ import {bootstrapApplication, provideProtractorTestingSupport} from '@angular/pl
import {init, syncUrlParamsToForm} from '../init';
import {AppComponent} from './app.component';
import {provideZoneChangeDetection} from '@angular/core';
syncUrlParamsToForm();
bootstrapApplication(AppComponent, {
providers: [provideProtractorTestingSupport()],
providers: [provideZoneChangeDetection(), provideProtractorTestingSupport()],
}).then(init);
+2 -1
View File
@@ -7,6 +7,7 @@
*/
import {bootstrapApplication, provideProtractorTestingSupport} from '@angular/platform-browser';
import {provideZoneChangeDetection} from '@angular/core';
import {init, syncUrlParamsToForm} from '../init';
@@ -15,5 +16,5 @@ import {AppComponent} from './app.component';
syncUrlParamsToForm();
bootstrapApplication(AppComponent, {
providers: [provideProtractorTestingSupport()],
providers: [provideZoneChangeDetection(), provideProtractorTestingSupport()],
}).then(init);
+2 -1
View File
@@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/
import {Component, NgModule} from '@angular/core';
import {Component, NgModule, provideZoneChangeDetection} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {BrowserModule} from '@angular/platform-browser';
@@ -87,5 +87,6 @@ export class AppComponent {
imports: [BrowserModule, FormsModule],
bootstrap: [AppComponent],
declarations: [AppComponent],
providers: [provideZoneChangeDetection()],
})
export class AppModule {}
@@ -6,11 +6,13 @@
* found in the LICENSE file at https://angular.dev/license
*/
import {enableProdMode} from '@angular/core';
import {enableProdMode, provideZoneChangeDetection} from '@angular/core';
import {bootstrapApplication} from '@angular/platform-browser';
import {init} from './init';
import {TableComponent} from './table';
enableProdMode();
bootstrapApplication(TableComponent).then(init);
bootstrapApplication(TableComponent, {
providers: [provideZoneChangeDetection()],
}).then(init);
@@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/
import {Component, Input, NgModule} from '@angular/core';
import {Component, Input, NgModule, provideZoneChangeDetection} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {emptyTable, TableCell} from '../util';
@@ -35,5 +35,10 @@ export class TableComponent {
}
}
@NgModule({imports: [BrowserModule], bootstrap: [TableComponent], declarations: [TableComponent]})
@NgModule({
imports: [BrowserModule],
bootstrap: [TableComponent],
providers: [provideZoneChangeDetection()],
declarations: [TableComponent],
})
export class AppModule {}
+7 -2
View File
@@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/
import {Component, NgModule} from '@angular/core';
import {Component, NgModule, provideZoneChangeDetection} from '@angular/core';
import {BrowserModule, DomSanitizer, SafeStyle} from '@angular/platform-browser';
import {emptyTree, TreeNode} from '../util';
@@ -29,7 +29,12 @@ export class TreeComponent {
}
}
@NgModule({imports: [BrowserModule], bootstrap: [TreeComponent], declarations: [TreeComponent]})
@NgModule({
imports: [BrowserModule],
providers: [provideZoneChangeDetection()],
bootstrap: [TreeComponent],
declarations: [TreeComponent],
})
export class AppModule {
constructor(sanitizer: DomSanitizer) {
trustedEmptyColor = sanitizer.bypassSecurityTrustStyle('');
@@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/
import {Component, Input, NgModule} from '@angular/core';
import {Component, Input, NgModule, provideZoneChangeDetection} from '@angular/core';
import {BrowserModule, DomSanitizer, SafeStyle} from '@angular/platform-browser';
import {emptyTree, getMaxDepth, TreeNode} from '../util';
@@ -57,6 +57,7 @@ export function createAppModule(): any {
imports: [BrowserModule],
bootstrap: [RootTreeComponent],
declarations: [components],
providers: [provideZoneChangeDetection()],
jit: true,
})
class AppModule {
@@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/
import {Component, Input, NgModule} from '@angular/core';
import {Component, Input, NgModule, provideZoneChangeDetection} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {emptyTree, TreeNode} from '../util';
@@ -29,5 +29,6 @@ export class TreeComponent {
imports: [BrowserModule],
bootstrap: [TreeComponent],
declarations: [TreeComponent],
providers: [provideZoneChangeDetection()],
})
export class AppModule {}
+2 -1
View File
@@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/
import {Component, NgModule} from '@angular/core';
import {Component, NgModule, provideZoneChangeDetection} from '@angular/core';
import {BrowserModule, platformBrowser} from '@angular/platform-browser';
@Component({
@@ -114,6 +114,7 @@ class AsyncApplication {
declarations: [AsyncApplication],
bootstrap: [AsyncApplication],
imports: [BrowserModule],
providers: [provideZoneChangeDetection()],
})
class ExampleModule {}
+2 -1
View File
@@ -7,7 +7,7 @@
*/
import {HttpClientModule} from '@angular/common/http';
import {NgModule} from '@angular/core';
import {NgModule, provideZoneChangeDetection} from '@angular/core';
import {BrowserModule, platformBrowser} from '@angular/platform-browser';
import {HttpCmp} from './app/http_comp';
@@ -16,6 +16,7 @@ import {HttpCmp} from './app/http_comp';
declarations: [HttpCmp],
bootstrap: [HttpCmp],
imports: [BrowserModule, HttpClientModule],
providers: [provideZoneChangeDetection()],
})
export class ExampleModule {}
+2 -1
View File
@@ -7,7 +7,7 @@
*/
import {HttpClientJsonpModule, HttpClientModule} from '@angular/common/http';
import {NgModule} from '@angular/core';
import {NgModule, provideZoneChangeDetection} from '@angular/core';
import {BrowserModule, platformBrowser} from '@angular/platform-browser';
import {JsonpCmp} from './app/jsonp_comp';
@@ -16,6 +16,7 @@ import {JsonpCmp} from './app/jsonp_comp';
bootstrap: [JsonpCmp],
declarations: [JsonpCmp],
imports: [BrowserModule, HttpClientModule, HttpClientJsonpModule],
providers: [provideZoneChangeDetection()],
})
export class ExampleModule {}
@@ -13,7 +13,15 @@ import {
} from '../src/animations';
import {AnimationDriver} from '../browser';
import {MockAnimationDriver} from '../browser/testing';
import {Component, NgZone, RendererFactory2, ViewChild, DOCUMENT} from '@angular/core';
import {
Component,
NgZone,
RendererFactory2,
ViewChild,
DOCUMENT,
NgModule,
provideZonelessChangeDetection,
} from '@angular/core';
import {fakeAsync, flushMicrotasks, TestBed} from '@angular/core/testing';
import {ɵDomRendererFactory2 as DomRendererFactory2} from '@angular/platform-browser';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
@@ -21,6 +29,11 @@ import {ɵAsyncAnimationRendererFactory as AsyncAnimationRendererFactory} from '
import {BrowserTestingModule, platformBrowserTesting} from '@angular/platform-browser/testing';
import {isNode} from '@angular/private/testing';
@NgModule({
providers: [provideZonelessChangeDetection()],
})
class TestModule {}
describe('BrowserAnimationBuilder', () => {
if (isNode) {
// Jasmine will throw if there are no tests.
@@ -233,7 +246,7 @@ describe('BrowserAnimationBuilder', () => {
// We need to reset the test environment because
// browser_tests.init.ts inits the environment with the NoopAnimationsModule
TestBed.resetTestEnvironment();
TestBed.initTestEnvironment([BrowserTestingModule], platformBrowserTesting());
TestBed.initTestEnvironment([BrowserTestingModule, TestModule], platformBrowserTesting());
});
it('should throw an error when injecting AnimationBuilder without animation providers set', () => {
@@ -246,7 +259,7 @@ describe('BrowserAnimationBuilder', () => {
// We're reset the test environment to their default values, cf browser_tests.init.ts
TestBed.resetTestEnvironment();
TestBed.initTestEnvironment(
[BrowserTestingModule, NoopAnimationsModule],
[BrowserTestingModule, NoopAnimationsModule, TestModule],
platformBrowserTesting(),
);
});
@@ -18,6 +18,7 @@ describe('binding to CSS class list', () => {
}
function detectChangesAndExpectClassName(classes: string): void {
fixture?.changeDetectorRef.markForCheck();
fixture!.detectChanges();
let nonNormalizedClassName = fixture!.debugElement.children[0].nativeElement.className;
expect(normalizeClassNames(nonNormalizedClassName)).toEqual(normalizeClassNames(classes));
@@ -395,8 +396,10 @@ describe('binding to CSS class list', () => {
detectChangesAndExpectClassName('');
fixture.componentInstance.condition = false;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
fixture.componentInstance.condition = true;
fixture.changeDetectorRef.markForCheck();
detectChangesAndExpectClassName('color-red');
});
@@ -478,6 +481,7 @@ describe('binding to CSS class list', () => {
expect(fixture.nativeElement.firstChild.className).toBe('option-1');
fixture.componentInstance.level = 5;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement.firstChild.className).toBe('option-5');
});
@@ -43,6 +43,7 @@ describe('insert/remove', () => {
let fixture = TestBed.createComponent(TestComponent);
fixture.componentInstance.currentComponent = null;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('');
@@ -56,6 +57,7 @@ describe('insert/remove', () => {
fixture.componentInstance.currentComponent = InjectedComponent;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('foo');
}));
@@ -67,6 +69,7 @@ describe('insert/remove', () => {
expect(fixture.nativeElement).toHaveText('');
fixture.componentInstance.cmpRef = undefined;
fixture.changeDetectorRef.markForCheck();
fixture.componentInstance.currentComponent = InjectedComponent;
fixture.detectChanges();
@@ -83,11 +86,13 @@ describe('insert/remove', () => {
fixture.componentInstance.currentComponent = InjectedComponent;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('foo');
fixture.componentInstance.currentComponent = null;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('');
}));
@@ -100,11 +105,13 @@ describe('insert/remove', () => {
fixture.componentInstance.currentComponent = InjectedComponent;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('foo');
fixture.componentInstance.currentComponent = InjectedComponentAgain;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('bar');
}));
@@ -119,6 +126,7 @@ describe('insert/remove', () => {
parent: fixture.componentRef.injector,
});
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
let cmpRef: ComponentRef<InjectedComponent> = fixture.componentInstance.cmpRef!;
expect(cmpRef).toBeInstanceOf(ComponentRef);
@@ -142,6 +150,7 @@ describe('insert/remove', () => {
environmentInjector,
);
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
let cmpRef: ComponentRef<InjectedComponent> = fixture.componentInstance.cmpRef!;
expect(cmpRef).toBeInstanceOf(ComponentRef);
@@ -155,6 +164,7 @@ describe('insert/remove', () => {
// We are accessing a ViewChild (ngComponentOutlet) before change detection has run
fixture.componentInstance.cmpRef = undefined;
fixture.componentInstance.currentComponent = InjectedComponent;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
let cmpRef: ComponentRef<InjectedComponent> = fixture.componentInstance.cmpRef!;
expect(cmpRef).toBeInstanceOf(ComponentRef);
@@ -183,6 +193,7 @@ describe('insert/remove', () => {
.rootNodes,
];
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('projected foo');
}));
@@ -196,6 +207,7 @@ describe('insert/remove', () => {
fixture.componentInstance.ngModule = TestModule2;
fixture.componentInstance.currentComponent = Module2InjectedComponent;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('baz');
}));
@@ -218,12 +230,14 @@ describe('insert/remove', () => {
const fixture = TestBed.createComponent(TestComponent);
fixture.componentInstance.ngModule = TestModule2;
fixture.componentInstance.currentComponent = Module2InjectedComponent;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('baz');
fixture.componentInstance.ngModule = TestModule3;
fixture.componentInstance.currentComponent = Module3InjectedComponent;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('bat');
@@ -240,6 +254,7 @@ describe('insert/remove', () => {
providers: [{provide: TEST_TOKEN, useValue: 'child'}],
parent: fixture.componentInstance.vcRef.injector,
});
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('Value: child');
@@ -274,6 +289,7 @@ describe('insert/remove', () => {
expect(outlet.componentInstance).toBeNull();
fixture.componentInstance.currentComponent = InjectedComponent;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(outlet.componentInstance).toBeInstanceOf(InjectedComponent);
@@ -284,31 +300,37 @@ describe('inputs', () => {
it('should be binding the component input', () => {
const fixture = TestBed.createComponent(TestInputsComponent);
fixture.componentInstance.currentComponent = ComponentWithInputs;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement.textContent).toBe('foo: , bar: , baz: Baz');
fixture.componentInstance.inputs = {};
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement.textContent).toBe('foo: , bar: , baz: Baz');
fixture.componentInstance.inputs = {foo: 'Foo', bar: 'Bar'};
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement.textContent).toBe('foo: Foo, bar: Bar, baz: Baz');
fixture.componentInstance.inputs = {foo: 'Foo'};
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement.textContent).toBe('foo: Foo, bar: , baz: Baz');
fixture.componentInstance.inputs = {foo: 'Foo', baz: null};
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement.textContent).toBe('foo: Foo, bar: , baz: ');
fixture.componentInstance.inputs = undefined;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement.textContent).toBe('foo: , bar: , baz: ');
@@ -317,21 +339,25 @@ describe('inputs', () => {
it('should be binding the component input (with mutable inputs)', () => {
const fixture = TestBed.createComponent(TestInputsComponent);
fixture.componentInstance.currentComponent = ComponentWithInputs;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement.textContent).toBe('foo: , bar: , baz: Baz');
fixture.componentInstance.inputs = {foo: 'Hello', bar: 'World'};
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement.textContent).toBe('foo: Hello, bar: World, baz: Baz');
fixture.componentInstance.inputs['bar'] = 'Angular';
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement.textContent).toBe('foo: Hello, bar: Angular, baz: Baz');
delete fixture.componentInstance.inputs['foo'];
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement.textContent).toBe('foo: , bar: Angular, baz: Baz');
@@ -341,11 +367,13 @@ describe('inputs', () => {
const fixture = TestBed.createComponent(TestInputsComponent);
fixture.componentInstance.currentComponent = ComponentWithInputs;
fixture.componentInstance.inputs = {foo: 'Foo', bar: 'Bar'};
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement.textContent).toBe('foo: Foo, bar: Bar, baz: Baz');
fixture.componentInstance.currentComponent = AnotherComponentWithInputs;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement.textContent).toBe('[ANOTHER] foo: Foo, bar: Bar, baz: Baz');
@@ -22,6 +22,7 @@ describe('ngFor', () => {
}
function detectChangesAndExpectText(text: string): void {
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText(text);
}
@@ -300,6 +301,7 @@ describe('ngFor', () => {
'<ng-template let-item let-i="index" #tpl>{{i}}: {{item}};</ng-template>';
fixture = createTestComponent(template);
getComponent().items = ['a', 'b', 'c'];
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
detectChangesAndExpectText('0: a;1: b;2: c;');
}));
@@ -310,6 +312,7 @@ describe('ngFor', () => {
const template = `<p *ngFor="let item of items; trackBy: value"></p>`;
fixture = createTestComponent(template);
fixture.componentInstance.value = 0;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
}));
@@ -329,6 +332,7 @@ describe('ngFor', () => {
fixture = createTestComponent(template);
thisArg = null;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(thisArg).toBe(getComponent());
}));
@@ -339,6 +343,7 @@ describe('ngFor', () => {
const buildItemList = () => {
getComponent().items = [{'id': 'a'}];
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
return fixture.debugElement.queryAll(By.css('p'))[0];
};
@@ -381,8 +386,10 @@ describe('ngFor', () => {
fixture = createTestComponent(template);
getComponent().items = ['a', 'b', 'c', 'd'];
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
getComponent().items = ['e', 'f', 'g', 'h'];
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
getComponent().items = ['e', 'f', 'h'];
detectChangesAndExpectText('efh');
@@ -7,7 +7,7 @@
*/
import {CommonModule, NgIf} from '../../index';
import {Component} from '@angular/core';
import {Component, provideZoneChangeDetection} from '@angular/core';
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {expect} from '@angular/private/testing/matchers';
@@ -27,6 +27,7 @@ describe('ngIf directive', () => {
TestBed.configureTestingModule({
declarations: [TestComponent],
imports: [CommonModule],
providers: [provideZoneChangeDetection()],
});
});
@@ -6,7 +6,14 @@
* found in the LICENSE file at https://angular.dev/license
*/
import {ChangeDetectionStrategy, Component, PLATFORM_ID, Provider, Type} from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
PLATFORM_ID,
Provider,
provideZoneChangeDetection,
Type,
} from '@angular/core';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {DomSanitizer, SafeResourceUrl} from '@angular/platform-browser';
import {isBrowser, isNode, withHead} from '@angular/private/testing';
@@ -34,6 +41,12 @@ import {
import {PRECONNECT_CHECK_BLOCKLIST} from '../../src/directives/ng_optimized_image/preconnect_link_checker';
describe('Image directive', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [provideZoneChangeDetection()],
});
});
const PLACEHOLDER_BLUR_AMOUNT = 15;
describe('preload <link> element on a server', () => {
@@ -19,6 +19,7 @@ describe('ngPlural', () => {
}
function detectChangesAndExpectText<T>(text: string): void {
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText(text);
}
@@ -47,11 +47,13 @@ describe('NgStyle', () => {
fixture = createTestComponent(template);
getComponent().expr = {'max-width': '40px'};
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expectNativeEl(fixture).toHaveCssStyle({'max-width': '40px'});
let expr = getComponent().expr;
expr['max-width'] = '30%';
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expectNativeEl(fixture).toHaveCssStyle({'max-width': '30%'});
}));
@@ -61,10 +63,12 @@ describe('NgStyle', () => {
fixture = createTestComponent(template);
getComponent().expr = {'max-width': '40px'};
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expectNativeEl(fixture).toHaveCssStyle({'max-width': '40px'});
getComponent().expr = null;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expectNativeEl(fixture).not.toHaveCssStyle('max-width');
}));
@@ -74,10 +78,12 @@ describe('NgStyle', () => {
fixture = createTestComponent(template);
getComponent().expr = {'max-width': '40px'};
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expectNativeEl(fixture).toHaveCssStyle({'max-width': '40px'});
getComponent().expr = undefined;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expectNativeEl(fixture).not.toHaveCssStyle('max-width');
}));
@@ -88,10 +94,12 @@ describe('NgStyle', () => {
fixture = createTestComponent(template);
getComponent().expr = '40';
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expectNativeEl(fixture).toHaveCssStyle({'max-width': '40px'});
getComponent().expr = null;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expectNativeEl(fixture).not.toHaveCssStyle('max-width');
}));
@@ -101,10 +109,12 @@ describe('NgStyle', () => {
fixture = createTestComponent(`<div [ngStyle]="{'color': expr}"></div>`);
getComponent().expr = 'green';
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expectNativeEl(fixture).toHaveCssStyle({'color': 'green'});
getComponent().expr = null;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expectNativeEl(fixture).not.toHaveCssStyle('color');
}));
@@ -115,10 +125,12 @@ describe('NgStyle', () => {
fixture = createTestComponent(template);
getComponent().expr = {'max-width.px': '40'};
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expectNativeEl(fixture).toHaveCssStyle({'max-width': '40px'});
getComponent().expr = {'max-width.em': '40'};
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expectNativeEl(fixture).toHaveCssStyle({'max-width': '40em'});
}));
@@ -135,6 +147,7 @@ describe('NgStyle', () => {
width: '10px',
};
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expectNativeEl(fixture).toHaveCssStyle({'height': '10px', 'width': '10px'});
@@ -144,6 +157,7 @@ describe('NgStyle', () => {
height: '5px',
};
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expectNativeEl(fixture).toHaveCssStyle({'height': '5px', 'width': '5px'});
}));
@@ -154,10 +168,12 @@ describe('NgStyle', () => {
fixture = createTestComponent(template);
getComponent().expr = {'max-width': '40px'};
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expectNativeEl(fixture).toHaveCssStyle({'max-width': '40px'});
delete getComponent().expr['max-width'];
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expectNativeEl(fixture).not.toHaveCssStyle('max-width');
}));
@@ -168,10 +184,12 @@ describe('NgStyle', () => {
fixture = createTestComponent(template);
getComponent().expr = {'max-width': '40px'};
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expectNativeEl(fixture).toHaveCssStyle({'max-width': '40px', 'font-size': '12px'});
delete getComponent().expr['max-width'];
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expectNativeEl(fixture).not.toHaveCssStyle('max-width');
expectNativeEl(fixture).toHaveCssStyle({'font-size': '12px'});
@@ -183,10 +201,12 @@ describe('NgStyle', () => {
fixture = createTestComponent(template);
getComponent().expr = {'max-width': '40px'};
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expectNativeEl(fixture).toHaveCssStyle({'max-width': '40px', 'font-size': '12px'});
delete getComponent().expr['max-width'];
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expectNativeEl(fixture).not.toHaveCssStyle('max-width');
expectNativeEl(fixture).toHaveCssStyle({'font-size': '12px'});
@@ -198,17 +218,20 @@ describe('NgStyle', () => {
fixture = createTestComponent(template);
fixture.componentInstance.expr = 'red';
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expectNativeEl(fixture).toHaveCssStyle({'color': 'red'});
// Overwrite native styles so that we can check if ngStyle has performed DOM manupulation to
// update it.
fixture.debugElement.children[0].nativeElement.style.color = 'blue';
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
// Assert that the style hasn't been updated
expectNativeEl(fixture).toHaveCssStyle({'color': 'blue'});
fixture.componentInstance.expr = 'yellow';
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
// Assert that the style has changed now that the model has changed
expectNativeEl(fixture).toHaveCssStyle({'color': 'yellow'});
@@ -219,6 +242,7 @@ describe('NgStyle', () => {
fixture = createTestComponent(template);
fixture.componentInstance.expr = 400;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expectNativeEl(fixture).toHaveCssStyle({'width': '400px'});
});
@@ -231,6 +255,7 @@ describe('NgStyle', () => {
const template = `<div style="width: var(--width)" [ngStyle]="{'--width': expr}"></div>`;
fixture = createTestComponent(template);
fixture.componentInstance.expr = '100px';
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
const target: HTMLElement = fixture.nativeElement.querySelector('div');
@@ -19,6 +19,7 @@ describe('NgSwitch', () => {
}
function detectChangesAndExpectText(text: string): void {
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText(text);
}
@@ -160,10 +161,12 @@ describe('NgSwitch', () => {
expect(fixture.nativeElement).toHaveText('when a');
fixture.componentInstance.switchValue = 'b';
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('when default');
fixture.componentInstance.switchValue = 'c';
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('when default');
});
@@ -32,6 +32,7 @@ describe('NgTemplateOutlet', () => {
}
function detectChangesAndExpectText(text: string): void {
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText(text);
}
@@ -313,6 +314,7 @@ describe('NgTemplateOutlet', () => {
const temp = componentInstance.context1;
componentInstance.context1 = componentInstance.context2;
componentInstance.context2 = temp;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(nativeElement.textContent.trim()).toBe('two | one');
@@ -393,6 +395,7 @@ describe('NgTemplateOutlet', () => {
expect(fixture.nativeElement.textContent).toBe('Name:');
fixture.componentInstance.ctx = {$implicit: 'Angular'};
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement.textContent).toBe('Name:Angular');
@@ -71,10 +71,12 @@ describe('JsonPipe', () => {
const fixture = TestBed.createComponent(TestComp);
const mutable: number[] = [1];
fixture.componentInstance.data = mutable;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('[\n 1\n]');
mutable.push(2);
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('[\n 1,\n 2\n]');
}));
@@ -107,10 +107,12 @@ describe('SlicePipe', () => {
const fixture = TestBed.createComponent(TestComp);
const mutable: number[] = [1, 2];
fixture.componentInstance.data = mutable;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('2');
mutable.push(3);
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
expect(fixture.nativeElement).toHaveText('2,3');
}));
@@ -29,6 +29,7 @@ import {
effect,
inject,
signal,
provideZoneChangeDetection,
} from '../../src/core';
import {NoopNgZone} from '../../src/zone/ng_zone';
import {TestBed} from '../../testing';
@@ -46,6 +47,11 @@ function createAndAttachComponent<T>(component: Type<T>) {
}
describe('after render hooks', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [provideZoneChangeDetection()],
});
});
let prev: boolean;
describe('browser', () => {

Some files were not shown because too many files have changed in this diff Show More