fix(router): reset the missing error boundaries warning in tests

The dev-mode warning for a route with an `errorComponent` but no
`withErrorBoundaries()` tracks whether it has fired in a module-level
variable. Spec order then decided whether the warning test saw it, so
it failed whenever another spec hit the same case first.

Add a private reset function and call it before the spec. Also make the
spec count only the matching warnings, since other `console.warn` calls
can run during the test.

Fixes the CI breakage from the previous change.
This commit is contained in:
Kam
2026-11-16 11:54:06 -08:00
committed by Alon Mishne
parent 1e6afa4cb8
commit 04dd9cf2a3
2 changed files with 11 additions and 3 deletions
@@ -44,6 +44,10 @@ import {PRIMARY_OUTLET} from '../shared';
let warnedAboutMissingErrorBoundaries = false;
export function resetMissingErrorBoundariesWarning(): void {
warnedAboutMissingErrorBoundaries = false;
}
/**
* An `InjectionToken` provided by the `RouterOutlet` and can be set using the `routerOutletData`
* input.
@@ -37,7 +37,7 @@ import {
withErrorBoundaries,
withRouterResources,
} from '../../index';
import {INPUT_BINDER} from '../../src/directives/router_outlet';
import {INPUT_BINDER, resetMissingErrorBoundariesWarning} from '../../src/directives/router_outlet';
import {RouterTestingHarness} from '../../testing';
export function provideRouter(
@@ -2323,6 +2323,8 @@ describe('Error boundaries and errorComponent integration', () => {
describe('errorComponent without error boundaries', () => {
useAutoTick();
beforeEach(() => resetMissingErrorBoundariesWarning());
it('warns once in dev mode when a route defines errorComponent without withErrorBoundaries', async () => {
@Component({template: 'Content'})
class RouteComponent {}
@@ -2345,8 +2347,10 @@ describe('errorComponent without error boundaries', () => {
await harness.navigateByUrl('/one');
await harness.navigateByUrl('/two');
expect(warn).toHaveBeenCalledTimes(1);
expect(warn.calls.mostRecent().args[0]).toContain(`'withErrorBoundaries()'`);
const warnings = warn.calls
.allArgs()
.filter(([message]) => String(message).includes(`'withErrorBoundaries()'`));
expect(warnings.length).toBe(1);
});
});