fix(core): run APP_INITIALIZERs 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:
Andrew Kushnir
2020-03-24 17:19:47 -07:00
committed by Alex Rickabaugh
parent 60adc35d30
commit 5c28af0e74
2 changed files with 22 additions and 5 deletions

View File

@ -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;
}