fix(core): run APP_INITIALIZER
s before accessing LOCALE_ID
token in Ivy TestBed (#36237)
Prior to this commit, Ivy TestBed was accessing locale ID before `APP_INITIALIZER` functions were called. This execution order is not consistent with the app bootstrap logic in `application_ref.ts`. This commit updates Ivy TestBed execution order to call initializers first (since they might affect `LOCALE_ID` token value) and accessing and setting locale ID after that. Fixes #36230. PR Close #36237
This commit is contained in:

committed by
Alex Rickabaugh

parent
60adc35d30
commit
5c28af0e74
@ -257,14 +257,16 @@ export class R3TestBedCompiler {
|
||||
const parentInjector = this.platform.injector;
|
||||
this.testModuleRef = new NgModuleRef(this.testModuleType, parentInjector);
|
||||
|
||||
// Set the locale ID, it can be overridden for the tests
|
||||
const localeId = this.testModuleRef.injector.get(LOCALE_ID, DEFAULT_LOCALE_ID);
|
||||
setLocaleId(localeId);
|
||||
|
||||
// ApplicationInitStatus.runInitializers() is marked @internal to core.
|
||||
// Cast it to any before accessing it.
|
||||
(this.testModuleRef.injector.get(ApplicationInitStatus) as any).runInitializers();
|
||||
|
||||
// Set locale ID after running app initializers, since locale information might be updated while
|
||||
// running initializers. This is also consistent with the execution order while bootstrapping an
|
||||
// app (see `packages/core/src/application_ref.ts` file).
|
||||
const localeId = this.testModuleRef.injector.get(LOCALE_ID, DEFAULT_LOCALE_ID);
|
||||
setLocaleId(localeId);
|
||||
|
||||
return this.testModuleRef;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user