diff --git a/packages/mock/src/msw/index.ts b/packages/mock/src/msw/index.ts index d5cc29e07..b01657ca5 100644 --- a/packages/mock/src/msw/index.ts +++ b/packages/mock/src/msw/index.ts @@ -110,11 +110,10 @@ const generateDefinition = ( const infoParam = isHandlerOverridden ? 'info' : ''; const handlerImplementation = ` export const ${handlerName} = (${isHandlerOverridden ? `overrideResponse?: ${returnType} | ((${infoParam}: Parameters[1]>[0]) => Promise<${returnType}> | ${returnType})` : ''}) => { - return http.${verb}('${route}', ${ - delay === false - ? `(${infoParam}) => {` - : `async (${infoParam}) => { - await delay(${isFunction(delay) ? `(${delay})()` : delay});` + return http.${verb}('${route}', ${(isReturnHttpResponse && !isTextPlain) || delay !== false ? 'async' : ''} (${infoParam}) => {${ + delay !== false + ? `await delay(${isFunction(delay) ? `(${delay})()` : delay});` + : '' } return new HttpResponse(${ isReturnHttpResponse