|
8 | 8 |
|
9 | 9 | import {DOCUMENT} from '@angular/common'; |
10 | 10 | import {provideLocationMocks} from '@angular/common/testing'; |
11 | | -import {Component, Inject, Injectable, NgModule} from '@angular/core'; |
| 11 | +import {Component, inject, Inject, Injectable, NgModule} from '@angular/core'; |
| 12 | +import {takeUntilDestroyed} from '@angular/core/rxjs-interop'; |
12 | 13 | import {fakeAsync, TestBed, tick} from '@angular/core/testing'; |
13 | | -import {Router, RouterModule, RouterStateSnapshot, TitleStrategy, withRouterConfig} from '@angular/router'; |
14 | | - |
15 | | -import {provideRouter} from '../src/provide_router'; |
| 14 | +import {ActivatedRoute, provideRouter, ResolveFn, Router, RouterModule, RouterStateSnapshot, TitleStrategy, withRouterConfig} from '@angular/router'; |
| 15 | +import {RouterTestingHarness} from '@angular/router/testing'; |
16 | 16 |
|
17 | 17 | describe('title strategy', () => { |
18 | 18 | describe('DefaultTitleStrategy', () => { |
@@ -114,6 +114,31 @@ describe('title strategy', () => { |
114 | 114 | await router.navigateByUrl('home'); |
115 | 115 | expect(router.routerState.snapshot.root.firstChild!.title).toEqual('My Application'); |
116 | 116 | }); |
| 117 | + |
| 118 | + it('pushes updates through the title observable', async () => { |
| 119 | + @Component({template: '', standalone: true}) |
| 120 | + class HomeCmp { |
| 121 | + private readonly title$ = inject(ActivatedRoute).title.pipe(takeUntilDestroyed()); |
| 122 | + title?: string; |
| 123 | + |
| 124 | + constructor() { |
| 125 | + this.title$.subscribe(v => this.title = v); |
| 126 | + } |
| 127 | + } |
| 128 | + const titleResolver: ResolveFn<string> = route => route.queryParams.id; |
| 129 | + router.resetConfig([{ |
| 130 | + path: 'home', |
| 131 | + title: titleResolver, |
| 132 | + component: HomeCmp, |
| 133 | + runGuardsAndResolvers: 'paramsOrQueryParamsChange' |
| 134 | + }]); |
| 135 | + |
| 136 | + const harness = await RouterTestingHarness.create(); |
| 137 | + const homeCmp = await harness.navigateByUrl('/home?id=1', HomeCmp); |
| 138 | + expect(homeCmp.title).toEqual('1'); |
| 139 | + await harness.navigateByUrl('home?id=2'); |
| 140 | + expect(homeCmp.title).toEqual('2'); |
| 141 | + }); |
117 | 142 | }); |
118 | 143 |
|
119 | 144 | describe('custom strategies', () => { |
|
0 commit comments