重试

模拟重连时间。

你可以通过向客户端发送 retry 消息来模拟服务器的重连时间指令。如果底层连接丢失,retry 键的值将控制重新连接的时间。

¥You can mock the reconnection time instruction from the server by sending the retry message to the client. The value of the retry key will control the reconnection time if the underlying connection is lost.

import { sse } from 'msw'
 
export const handlers = [
  sse('/stream', ({ client }) => {
    client.send({ retry: 1000 })
  }),
]

这将导致客户端收到以下消息:

¥This will result in the following message received by the client:

retry:1000