Reputation: 1
getting error when i try to run test cases
import { Test } from '@nestjs/testing';
import { appConfig } from '../app.config';
import { CommonBotModule } from '../common/common-bot.module';
import { CredentialsManagerModule } from '../credentials/credentials-manager.module';
import { BotModule } from './bot.module';
import { I18nService } from 'nestjs-i18n';
jest.mock('aws-sdk'); // Prevent DynamoDB connect
jest.mock('@aws/dynamodb-data-mapper'); // Prevent DynamoDB connect
jest.mock('kafkajs');
jest.mock('../cache/cacheConfig.service'); // Prevent Redis connect
describe('bot.module.ts', () => {
beforeAll(() => {
config.init(appConfig);
});
it('The bot module should be able to be compiled', async () => {
const botModule = await Test.createTestingModule({
imports: [CommonBotModule, CredentialsManagerModule, BotModule, I18nService]
}).compile();
expect(botModule).toBeDefined();
});
});
error :
Nest can't resolve dependencies of the I18nService (?, I18nTranslations, I18nLanguages, Logger, I18nLoader, I18nLanguagesSubject, I18nTranslationsSubject). Please make sure that the argument I18nOptions at index [0] is available in the I18nService context.
Potential solutions:
- If I18nOptions is a provider, is it part of the current I18nService?
- If I18nOptions is exported from a separate @Module, is that module imported within I18nService?
@Module({
imports: [ /* the Module containing I18nOptions */ ]
})
Upvotes: 0
Views: 153
Reputation: 6695
you're registering a 3rd-party provider. That I18nService
will be registered by some nestjs module from nestjs-i18n
package, so you shouldn't have it in your array.
If you do want to use the I18nService
as a provider token for a mock value, you can do:
{
provide: I18nService,
useValue: yourFakeObjectHere,
}
There are other ways to achieve that. Read the docs: https://docs.nestjs.com/fundamentals/testing
Upvotes: 0