在我的测试代码中,我检查断言所有 nocks 已被调用,如果没有调用 nock,我有一个半有用的错误消息要转储出来(因为默认错误消息是无用的):
try {
assertions(data, result);
if (assertNock !== null) {
// Expect that all mocked calls were made
if (nock.isDone() !== !!assertNock) {
console.error('One or more of your Nock matchers was never called.');
}
expect(nock.isDone()).toBe(!!assertNock);
}
done();
} catch (err) {
...
}
但是,我希望能够指定未拨打的电话。但是,我似乎找不到从nock
对象中获取该信息的方法,如下所示:
{ [Function: startScope]
emitter:
EventEmitter {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined },
define: [Function: define],
loadDefs: [Function: loadDefs],
load: [Function: load],
enableNetConnect: [Function: enableNetConnect],
disableNetConnect: [Function: disableNetConnect],
removeInterceptor: [Function: removeInterceptor],
activeMocks: [Function: activeMocks],
pendingMocks: [Function: pendingMocks],
isDone: [Function: isDone],
isActive: [Function: isActive],
activate: [Function: activate],
cleanAll: [Function: cleanAll],
recorder:
{ rec: [Function: record],
clear: [Function: clear],
play: [Function] },
back: { [Function: Back] setMode: [Function], fixtures: null, currentMode: 'dryrun' },
restore: [Function: restore]
}
如何获得有关不是从 nock 对象发出的请求的有用/识别信息?