-
-
Notifications
You must be signed in to change notification settings - Fork 351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(msw): make delay optional #1360
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -94,11 +94,15 @@ const generateDefinition = ( | |||||||||||||||||||||||||
? `export const ${getResponseMockFunctionName} = (${isResponseOverridable ? `overrideResponse: any = {}` : ''})${mockData ? '' : `: ${returnType}`} => (${value})\n\n` | ||||||||||||||||||||||||||
: ''; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const delayTime = getDelay(override, !isFunction(mock) ? mock : undefined); | ||||||||||||||||||||||||||
const delay = getDelay(override, !isFunction(mock) ? mock : undefined); | ||||||||||||||||||||||||||
const handlerImplementation = ` | ||||||||||||||||||||||||||
export const ${handlerName} = (${isReturnHttpResponse && !isTextPlain ? `overrideResponse?: ${returnType}` : ''}) => { | ||||||||||||||||||||||||||
return http.${verb}('${route}', async () => { | ||||||||||||||||||||||||||
await delay(${isFunction(delayTime) ? `(${delayTime})()` : delayTime}); | ||||||||||||||||||||||||||
return http.${verb}('${route}', ${ | ||||||||||||||||||||||||||
delay === false | ||||||||||||||||||||||||||
? '() => {' | ||||||||||||||||||||||||||
: `async () => { | ||||||||||||||||||||||||||
await delay(${isFunction(delay) ? `(${delay})()` : delay});` | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
Comment on lines
+100
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought that the definition itself is unnecessary if
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, the second argument to http.get must be a function, so we cannot remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, that's nice. That's what I wanted. |
||||||||||||||||||||||||||
return new HttpResponse(${ | ||||||||||||||||||||||||||
isReturnHttpResponse | ||||||||||||||||||||||||||
? isTextPlain | ||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit unsure about this, but it feels like override always should override when present, and not only when it's overridden by a number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. Not sure why this decision was made?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it was missed when support for functions was added?