mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
eae75ff3f9
Previously, `RouterLinkActive` would only add or remove the active classes when its active state changed. This means that if you accidentally add one of the active classes to the static class attribute, it won't get removed until the link becomes active and then deactives (because the class is added at creation time and never removed until the `RouterLinkActive` state changes from active to inactive). fixes #54978 PR Close #54982
29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
import {Component} from '@angular/core';
|
|
import {TestBed} from '@angular/core/testing';
|
|
import {Router, RouterLink, RouterLinkActive, provideRouter} from '@angular/router';
|
|
|
|
describe('RouterLinkActive', () => {
|
|
it('removes initial active class even if never active', async () => {
|
|
@Component({
|
|
standalone: true,
|
|
imports: [RouterLinkActive, RouterLink],
|
|
template: '<a class="active" routerLinkActive="active" routerLink="/abc123"></a>',
|
|
})
|
|
class MyCmp {}
|
|
|
|
TestBed.configureTestingModule({providers: [provideRouter([{path: '**', children: []}])]});
|
|
const fixture = TestBed.createComponent(MyCmp);
|
|
fixture.autoDetectChanges();
|
|
await TestBed.inject(Router).navigateByUrl('/');
|
|
await fixture.whenStable();
|
|
expect(Array.from(fixture.nativeElement.querySelector('a').classList)).toEqual([]);
|
|
});
|
|
});
|