how do you solve missing locale from CLDR in angular 5 in unit tests?
I have in app.module
registerLocaleData(...)
and it works for the app, however when I run unit tests where I use pipes with locale, it doesn't know about app.module
.
It sounds weird to load these locales in each test. I tried to import it in test.ts
but with no luck.
Any ideas?
Unit tests run against specific lines of code. So it makes sense to place them right next to that code. Integration tests run against many lines of code in many files. There is no single place that would make sense, so it's best to have them in a /tests directory.
Angular uses the Unicode locale identifier (Unicode locale ID) to find the correct locale data for internationalization of text strings. Unicode locale ID. A locale ID conforms to the Unicode Common Locale Data Repository (CLDR) core specification.
spec. ts file. This file contains unit tests for the main AppComponent. When running tests using the Angular CLI, all unit tests in files with the *. spec.
I had the same issue. Fixed it by modifying test.ts like so:
...
// Add these two imports
import { registerLocaleData } from '@angular/common';
import localeDe from '@angular/common/locales/de';
...
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Add this line to register a locale (german in this case).
registerLocaleData(localeDe);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With