Document hard-coded implicit delay in Node.js #376
-
FeedbackIt says that it waits function getRealisticResponseTime(): number {
if (isNodeProcess()) {
return NODE_SERVER_RESPONSE_TIME
}
return Math.floor(
Math.random() * (MAX_SERVER_RESPONSE_TIME - MIN_SERVER_RESPONSE_TIME) +
MIN_SERVER_RESPONSE_TIME,
)
} So if it's determined to be a node process, it always returns |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, @jlissner. Thanks for bringing this up. Yes, that's indeed an implicit feature designed to provide a better testing experience since in the light of how the realistic server response time is used with the MSW intends that use case to enable server-like response times when developing, but when testing you want your network to be fast. That's why we preemptively hard-code the realistic response time to a fixed value when run in Node.js. Your tests should be reliable and reproducible, which means a reliable and reproducible network that MSW aims to provide, including the fixed response timing when using the You can opt-out from this by providing an explicit delay duration to the I do believe this behavior makes sense, we just need to document it better on the website. |
Beta Was this translation helpful? Give feedback.
Hi, @jlissner. Thanks for bringing this up.
Yes, that's indeed an implicit feature designed to provide a better testing experience since in the light of how the realistic server response time is used with the
delay()
function.MSW intends that use case to enable server-like response times when developing, but when testing you want your network to be fast. That's why we preemptively hard-code the realistic response time to a fixed value when run in Node.js. Your tests should be reliable and reproducible, which means a reliable and reproducible network that MSW aims to provide, including the fixed response timing when using the
delay()
function without any arguments.You can opt-out from th…