Open MFrat opened 3 months ago
You might need to provide some additional context, like what you've tried in your unit test. I've setup a pattern along these lines with some success:
import { Test } from '@nestjs/testing';
import { getRedisConnectionToken } from '@nestjs-modules/ioredis';
describe('YourService', () => {
const redisMock = {}; // replace with your mock
beforeEach(async () => {
const moduleRef = await Test.createTestingModule({
providers: [
{
provide: getRedisConnectionToken(),
useValue: redisMock,
},
YourService,
],
}).compile();
});
// ...
});
It is not possible to mock
@InjectRedis() private readonly redis: Redis
in unit tests. The following error occurs: