From c41635bb1f01b93d1bcc88120ccf3c8d2e778b85 Mon Sep 17 00:00:00 2001 From: Shodai Suzuki Date: Mon, 22 Jan 2024 20:31:51 +0900 Subject: [PATCH] fix(mock): `null` is excluded instead of being converted to an empty string `''` (#1166) --- packages/mock/src/faker/getters/scalar.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/mock/src/faker/getters/scalar.ts b/packages/mock/src/faker/getters/scalar.ts index 74c381042..cdd88818d 100644 --- a/packages/mock/src/faker/getters/scalar.ts +++ b/packages/mock/src/faker/getters/scalar.ts @@ -211,8 +211,12 @@ export const getMockScalar = ({ if (item.enum) { // By default the value isn't a reference, so we don't have the object explicitly defined. // So we have to create an array with the enum values and force them to be a const. - let enumValue = - "['" + item.enum.map((e) => escape(e)).join("','") + "'] as const"; + const joindEnumValues = item.enum + .filter(Boolean) + .map((e) => escape(e)) + .join("','"); + + let enumValue = `['${joindEnumValues}'] as const`; // But if the value is a reference, we can use the object directly via the imports and using Object.values. if (item.isRef) {