Closed tristolliday closed 3 years ago
The test is complaining that Nest.js test instance doesn't recognise the ConfigService
that is injected into EncryptionService
. I must have left that test in by accident - it doesn't really test anything at the moment so you could either remove it for now, or add ConfigService
to the providers for the TestingModule:
import { ConfigService } from '@nestjs/config';
describe('EncryptionService', () => {
let service: EncryptionService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
ConfigService, // <-- injected into the encryption service
EncryptionService
],
}).compile();
service = module.get<EncryptionService>(EncryptionService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
Thanks for that, Jest still baffles me. Need to get my head around it. Cheers for the great template 👍
It's a weird one with Nest's Dependency Injection, if you have watched any of the live streams I did then you'll know it can be a pain to get your head around. When you create a test module you need to define all of the dependencies. Because I'm using the ConfigService to get the hash rounds before encrypting it needs to be defined somewhere within the app as a provider so Nest knows what to inject.
I'm glad you like the starter, I'd love to see what you make with it. Give us a shout when you're up and running, we'd be happy to help promote what you're working on on the Neo4j Developer Blog.
Upon cloning the project, the jest test immediately fails on encryption.service
This is after no amends to the project.
Any advice would be appreciated