Skip to content

Commit 44c8cf4

Browse files
authored
fix: use override for text/plain response types (#2123)
1 parent cecfb47 commit 44c8cf4

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

packages/mock/src/msw/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ const generateDefinition = (
128128

129129
const delay = getDelay(override, !isFunction(mock) ? mock : undefined);
130130
const infoParam = 'info';
131+
const overrideResponse = `overrideResponse !== undefined
132+
? (typeof overrideResponse === "function" ? await overrideResponse(${infoParam}) : overrideResponse)
133+
: ${getResponseMockFunctionName}()`;
131134
const handlerImplementation = `
132135
export const ${handlerName} = (overrideResponse?: ${returnType} | ((${infoParam}: Parameters<Parameters<typeof http.${verb}>[1]>[0]) => Promise<${returnType}> | ${returnType})) => {
133136
return http.${verb}('${route}', async (${infoParam}) => {${
@@ -139,10 +142,8 @@ export const ${handlerName} = (overrideResponse?: ${returnType} | ((${infoParam}
139142
return new HttpResponse(${
140143
isReturnHttpResponse
141144
? isTextPlain
142-
? `${getResponseMockFunctionName}()`
143-
: `JSON.stringify(overrideResponse !== undefined
144-
? (typeof overrideResponse === "function" ? await overrideResponse(${infoParam}) : overrideResponse)
145-
: ${getResponseMockFunctionName}())`
145+
? overrideResponse
146+
: `JSON.stringify(${overrideResponse})`
146147
: null
147148
},
148149
{ status: ${status === 'default' ? 200 : status.replace(/XX$/, '00')},

0 commit comments

Comments
 (0)