Open MikeDabrowski opened 1 year ago
We are also facing problems after the update to transloco v5/v6. We are also having a custom function which returns the TranslocoTestingModule.forRoot
.
Now we are getting NullInjectorError: No provider for InjectionToken TRANSLOCO_TRANSPILER!
in some tests.
Our testing module factory function looks like this at the moment:
import { TranslocoTestingModule } from '@ngneat/transloco';
export const getTranslocoTestingModule = (en = {}, de = {}) =>
TranslocoTestingModule.forRoot({
langs: { 'en-US': en, 'de-DE': de },
translocoConfig: {
defaultLang: 'en-US',
fallbackLang: 'en-US',
availableLangs: ['de-DE', 'en-US'],
missingHandler: { logMissingKey: false, useFallbackTranslation: false, allowEmpty: false },
},
preloadLangs: true,
});
@MikeDabrowski Would maybe something like this work for you to have additional providers on the module?
export function importTranslocoTestingModule(options: TranslocoTestingOptions = {}) {
const result = TranslocoTestingModule.forRoot({
translocoConfig: {
// ...
},
...options
});
result.providers = result.providers.concat(
provideTranslocoLocale({
// ...
}),
// ...
)
return result;
}
@krechtern We had the same issue - turns out we had not imported getTranslocoTestingModule()
in the failing tests at all. Not sure how it worked before, but checking all those tests and importing it resolved the issue for us.
Is there an existing issue for this?
Which Transloco package(s) will this feature affect?
Transloco
Is your feature request related to a problem? Please describe
In out app we use transloco + locale + messageFormat. We had to make some units that test those features so we have
This worked fine in v4 but upgrading it now to v5 and v6 presents some issues.
In v5+ default way of enabling transloco is using provider fns. But for test there stil is the testing module .forRoot. As you can see we used to import 3 modules, 2 of which are now moved to provider fns. The end goal here is to have a one line that can be used in TestBed's imports (or providers). So Custom testing module idea was born:
The providers are mostly copied from source of translocoTestingModule. However the problem now is - how to get the TRANSLOCO_TEST_LANGS and TRANSLOCO_TEST_OPTIONS
Describe the solution you'd like
At this point I am not sure what would help here.
Option 1
Would be to export the TRANSLOCO_TEST_LANGS, TRANSLOCO_TEST_OPTIONS and perhaps something else.
I tried manually adding exports in built packages but it failed with
Option 2
Would be to provide provider function for that translocoTesting module and add a way to provide additional providers.
Option 3
Do this in each place
Describe alternatives you've considered
Additional context
No response
I would like to make a pull request for this feature
No