Context
I'm trying to fail tests when unmatched recordings are present in the recording file when using nockBack.
Alternatives
I was hoping I could do something with before or after, but unfortunately they are not helpful.
Is there maybe a callback that one could use to count the amount of mocked requests?
Has the feature been requested before?
Not that I have seen.
If the feature request is accepted, would you be willing to submit a PR?
This shouldn't be a hard change. The big question is what to do and where to make it :)
Hi!
I've been doing some work on proposing some new lifecycle methods in #1474 (and #1441 before that). In #1441 there was discussion about adding a nock.assertMocksUsed() function which would assert that all mocks have been satisfied.
See https://github.com/nock/nock/blob/e644ff350de214823cf80d902df335e179da3928/rfcs/NOCK-001.md#analysis, where I talk about the current way to do this being scopes.forEach(scope => scope.done()). That wouldn't work for the nockBack case, though, since you probably don't have the scopes handy. I think instead you'd need to check that nock.pendingMocks() is empty.
@paulmelnikow Beauty! That works perfectly (see pr here).
Thank you very much for the help! If you think this is a duplicate ticket please feel free to close it,
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We try to do our best, but nock is maintained by volunteers and there is only so much we can do at a time. Thank you for your contributions.
Most helpful comment
Hi!
I've been doing some work on proposing some new lifecycle methods in #1474 (and #1441 before that). In #1441 there was discussion about adding a
nock.assertMocksUsed()function which would assert that all mocks have been satisfied.See https://github.com/nock/nock/blob/e644ff350de214823cf80d902df335e179da3928/rfcs/NOCK-001.md#analysis, where I talk about the current way to do this being
scopes.forEach(scope => scope.done()). That wouldn't work for thenockBackcase, though, since you probably don't have the scopes handy. I think instead you'd need to check thatnock.pendingMocks()is empty.