-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(config): add unit test for generic config service
- Loading branch information
1 parent
83a014c
commit 633465b
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { INestApplication } from '@nestjs/common'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { AppModule } from '../src/app.module'; | ||
import { ConfigService } from '../../lib'; | ||
|
||
describe('Optional Generic()', () => { | ||
let app: INestApplication; | ||
let module: TestingModule; | ||
|
||
beforeEach(async () => { | ||
module = await Test.createTestingModule({ | ||
imports: [AppModule.withEnvVars()], | ||
}).compile(); | ||
|
||
app = module.createNestApplication(); | ||
await app.init(); | ||
}); | ||
|
||
it(`should allow a key of the interface`, () => { | ||
const configService = module.get<ConfigService<{ PORT: string }>>( | ||
ConfigService, | ||
); | ||
|
||
const port = configService.get('PORT'); | ||
|
||
expect(port).toBeTruthy(); | ||
}); | ||
|
||
it(`should allow any key without a generic`, () => { | ||
const configService = module.get<ConfigService>(ConfigService); | ||
|
||
const port = configService.get('PORT'); | ||
|
||
expect(port).toBeTruthy(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await app.close(); | ||
}); | ||
}); |