Skip to content

Commit

Permalink
fix(msw): make sure method is async even when delay=false (#1440)
Browse files Browse the repository at this point in the history
Co-authored-by: Alfred Jonsson <alfred.jonsson@decerno.se>
  • Loading branch information
AllieJonsson and Alfred Jonsson authored Jun 7, 2024
1 parent 9c44e9e commit 991ac17
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/mock/src/msw/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,10 @@ const generateDefinition = (
const infoParam = isHandlerOverridden ? 'info' : '';
const handlerImplementation = `
export const ${handlerName} = (${isHandlerOverridden ? `overrideResponse?: ${returnType} | ((${infoParam}: Parameters<Parameters<typeof http.${verb}>[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
Expand Down

0 comments on commit 991ac17

Please sign in to comment.