Skip to content

Commit

Permalink
fix(msw): correctly mock nested objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfred Jonsson committed Apr 23, 2024
1 parent 5f5dc17 commit fd75eb6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/mock/src/faker/getters/combine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? []));
Expand All @@ -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) {
Expand Down

0 comments on commit fd75eb6

Please sign in to comment.