-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1346 from MatthiasKunnen/fix-process-env-undefine…
…d-assignment fix(): prevent unexpected process env stringification
- Loading branch information
Showing
2 changed files
with
40 additions
and
2 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
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,33 @@ | ||
import { Test } from '@nestjs/testing'; | ||
import { AppModule } from '../src/app.module'; | ||
import { ConfigService } from '../../lib'; | ||
|
||
describe('Optional environment variables', () => { | ||
it('should return undefined for optional variables', async () => { | ||
const module = await Test.createTestingModule({ | ||
imports: [AppModule.withValidateFunction(() => ({ | ||
optional: undefined, | ||
}))], | ||
}).compile(); | ||
|
||
const app = module.createNestApplication(); | ||
await app.init(); | ||
|
||
const optional = module.get(ConfigService).get('optional') | ||
|
||
expect(optional).toEqual(undefined) | ||
}); | ||
|
||
it('should not assign complex objects back to process.env', async () => { | ||
const module = await Test.createTestingModule({ | ||
imports: [AppModule.withValidateFunction(() => ({ | ||
complex: {hello: 'there'}, | ||
}))], | ||
}).compile(); | ||
|
||
const app = module.createNestApplication(); | ||
await app.init(); | ||
|
||
expect(process.env.complex).toEqual(undefined) | ||
}); | ||
}); |