Skip to content

Commit

Permalink
test(config): add unit test for generic config service
Browse files Browse the repository at this point in the history
  • Loading branch information
yharaskrik committed May 19, 2020
1 parent 83a014c commit 633465b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/e2e/optional-generic.spec.ts
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();
});
});

0 comments on commit 633465b

Please sign in to comment.