toonvanstrijp / nestjs-i18n

The i18n module for nestjs.
https://nestjs-i18n.com
Other
643 stars 108 forks source link

using the library with jest #465

Open ghost opened 1 year ago

ghost commented 1 year ago

how can i get its value for a service test by jest

itinance commented 1 year ago

I found a way to pass the I18nService into my services and on their corresponding unit-tests, I do:

    const module: TestingModule = await Test.createTestingModule({
      imports: [
        I18nModule.forRoot({
          fallbackLanguage: 'en-US',
          loaderOptions: {
            path: path.join(__dirname, '../locales'),
            watch: true,
          },
          resolvers: [{ use: QueryResolver, options: ['lang'] }],
        }),
      ],
      providers: [ExampleService],
    }).compile();

The drawback is that the translation can't be tested because the resolver won't work at this level. It will only return the passed key (although in the "normal" app-launch-mode, it all works), details here #495