Konrad Cerny
Konrad Cerny

Reputation: 200

Locale files for unit test in Angular 5

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?

Upvotes: 7

Views: 3511

Answers (1)

Pascal Chorus
Pascal Chorus

Reputation: 480

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);

Upvotes: 9

Related Questions