If you're encountering issues running unit tests with Jest and Transloco due to the flat library, try upgrading to Transloco v7.5.1, where the flat dependency has been removed.
When running tests, it's important to have the languages available immediately and synchronously. Transloco provides the TranslocoTestingModule, which allows you to specify the languages and configuration needed for your specs.
To follow the DRY (Don't Repeat Yourself) principle, it's a good idea to create a module factory function that can be reused in each spec. Here's an example:
transloco-testing.module.ts
import { TranslocoTestingModule, TranslocoTestingOptions } from'@jsverse/transloco';import en from'../assets/i18n/en.json';import es from'../assets/i18n/es.json';exportfunctiongetTranslocoModule(options:TranslocoTestingOptions= {}) {returnTranslocoTestingModule.forRoot({ langs: { en, es }, translocoConfig: { availableLangs: ['en','es'], defaultLang:'en', }, preloadLangs:true,...options, });}