From fd75eb66579a0d06c8bb54a790aa5d3c0bf910f4 Mon Sep 17 00:00:00 2001 From: Alfred Jonsson Date: Tue, 23 Apr 2024 10:18:44 +0200 Subject: [PATCH] fix(msw): correctly mock nested objects --- packages/mock/src/faker/getters/combine.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/mock/src/faker/getters/combine.ts b/packages/mock/src/faker/getters/combine.ts index 06169bc09..22dcfd2a7 100644 --- a/packages/mock/src/faker/getters/combine.ts +++ b/packages/mock/src/faker/getters/combine.ts @@ -94,6 +94,7 @@ export const combineSchemasMock = ({ imports, existingReferencedProperties, }); + console.log('val:', val, 'Mock value:', resolvedValue.value); combineImports.push(...resolvedValue.imports); includedProperties.push(...(resolvedValue.includedProperties ?? [])); @@ -103,9 +104,9 @@ export const combineSchemasMock = ({ let currentValue = resolvedValue.value; if (itemResolvedValue?.value && separator === 'oneOf') { - currentValue = `${resolvedValue.value.slice(0, -1)},${ - itemResolvedValue.value - }}`; + const s = resolvedValue.value.split('},{'); + const joined = s.join(`,${itemResolvedValue.value}},{`); + currentValue = `${joined.slice(0, -1)},${itemResolvedValue.value}}`; } if (itemResolvedValue?.value && separator !== 'oneOf' && isLastElement) {