Nock - 如何记录每个请求的状态?
Nock - how to log the status of each request?
我希望能够看到拦截器拦截的每个请求,并查看它是已响应还是待处理。我为每个拦截器使用 scope.persist(true)
。如何做到这一点?
Scope
s 在 Interceptor
与请求匹配并且 Interceptor
回复有效载荷时发出事件。
https://github.com/nock/nock#events
每个事件的回调都作为参数传递给 Interceptor
。
我不完全确定 "see whether it has responded or is pending" 周围的问题是什么,但这样的事情应该会让你继续:
const scope = nock('http://example.test')
.get('/')
.reply(200)
scope.on('request', (req, interceptor) => {
console.log('interceptor matched request', interceptor.uri)
});
scope.on('replied', (req, interceptor) => {
console.log('response replied with nocked payload', interceptor.uri)
});
我希望能够看到拦截器拦截的每个请求,并查看它是已响应还是待处理。我为每个拦截器使用 scope.persist(true)
。如何做到这一点?
Scope
s 在 Interceptor
与请求匹配并且 Interceptor
回复有效载荷时发出事件。
https://github.com/nock/nock#events
每个事件的回调都作为参数传递给 Interceptor
。
我不完全确定 "see whether it has responded or is pending" 周围的问题是什么,但这样的事情应该会让你继续:
const scope = nock('http://example.test')
.get('/')
.reply(200)
scope.on('request', (req, interceptor) => {
console.log('interceptor matched request', interceptor.uri)
});
scope.on('replied', (req, interceptor) => {
console.log('response replied with nocked payload', interceptor.uri)
});