Hi, I have a problem with my application tests after applying Zod.
I have a simple test, this one:
import { Test, TestingModule } from '@nestjs/testing';
import { MailerProcessor } from '../processors/mailer.processor';
describe('MailerService', () => {
let service: MailerProcessor;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [MailerProcessor],
}).compile();
service = module.get<MailerProcessor>(MailerProcessor);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
And my validation scheme is this (also simple):
import 'dotenv/config';
import { z } from 'zod';
interface EnvVars {
PORT: number;
TIMEOUT_REQUEST: number;
NODE_ENV: string;
}
const MIN_PORT_NUMBER: number = 3000;
const MAX_PORT_NUMBER: number = 65536;
const DEFAULT_TIMEOUT_REQUEST: number = 5000;
const envsSchema = z.object({
PORT: z.coerce
.number()
.positive()
.max(MAX_PORT_NUMBER, `Port should be >= 0 and < 65536`)
.default(MIN_PORT_NUMBER),
TIMEOUT_REQUEST: z.coerce
.number()
.positive()
.default(DEFAULT_TIMEOUT_REQUEST),
NODE_ENV: z.string().default('development'),
});
const envVars = envsSchema.parse({ ...process.env }) as EnvVars;
export const Envs = {
ENVIRONMENT: {
PORT: Number(envVars.PORT),
TIMEOUT_REQUEST: envVars.TIMEOUT_REQUEST,
NODE_ENV: envVars.NODE_ENV,
},
};