diff --git a/docs/api/MockAgent.md b/docs/api/MockAgent.md index a499818023a..25e39c4ace2 100644 --- a/docs/api/MockAgent.md +++ b/docs/api/MockAgent.md @@ -484,7 +484,7 @@ const pendingInterceptors = agent.pendingInterceptors() // ] ``` -### `MockAgent.assertNoUnusedInterceptors([options])` +### `MockAgent.assertNoPendingInterceptors([options])` This method throws if the mock agent has any pending (i.e., non-persistent and not fully consumed) interceptors. diff --git a/lib/mock/mock-agent.js b/lib/mock/mock-agent.js index aee0b26aa6f..3a5d9bd1230 100644 --- a/lib/mock/mock-agent.js +++ b/lib/mock/mock-agent.js @@ -11,8 +11,7 @@ const { kNetConnect, kGetNetConnect, kOptions, - kFactory, - kGetMockAgentClientsByConsumedStatus + kFactory } = require('./mock-symbols') const MockClient = require('./mock-client') const MockPool = require('./mock-pool') @@ -147,7 +146,7 @@ class MockAgent extends Dispatcher { // .filter(({ consumed, persist, timesInvoked }) => timesInvoked === 0 || !consumed) } - assertNoUnusedInterceptors (options = {}) { + assertNoPendingInterceptors (options = {}) { const pending = this.pendingInterceptors() if (pending.length === 0) { diff --git a/lib/mock/mock-symbols.js b/lib/mock/mock-symbols.js index a749c95273a..8c4cbb60e16 100644 --- a/lib/mock/mock-symbols.js +++ b/lib/mock/mock-symbols.js @@ -19,6 +19,5 @@ module.exports = { kIsMockActive: Symbol('is mock active'), kNetConnect: Symbol('net connect'), kGetNetConnect: Symbol('get net connect'), - kConnected: Symbol('connected'), - kGetMockAgentClientsByConsumedStatus: Symbol('get mock agent clients by consumed status') + kConnected: Symbol('connected') } diff --git a/test/mock-interceptor-unused-assertions.js b/test/mock-interceptor-unused-assertions.js index 79b381a5bbc..24fdafef193 100644 --- a/test/mock-interceptor-unused-assertions.js +++ b/test/mock-interceptor-unused-assertions.js @@ -38,7 +38,7 @@ function mockAgentWithOneInterceptor () { test('1 pending interceptor', t => { t.plan(2) - const err = t.throws(() => mockAgentWithOneInterceptor().assertNoUnusedInterceptors({ tableFormatter })) + const err = t.throws(() => mockAgentWithOneInterceptor().assertNoPendingInterceptors({ tableFormatter })) t.same(err.message, ` 1 interceptor is pending: @@ -59,7 +59,7 @@ test('2 pending interceptors', t => { .get(origin) .intercept({ method: 'get', path: '/some/path' }) .reply(204, 'OK') - const err = t.throws(() => withTwoInterceptors.assertNoUnusedInterceptors({ tableFormatter })) + const err = t.throws(() => withTwoInterceptors.assertNoPendingInterceptors({ tableFormatter })) t.same(err.message, ` 2 interceptors are pending: @@ -121,7 +121,7 @@ test('Variations of persist(), times(), and pending status', async t => { t.same((await agent.request({ origin, method: 'GET', path: '/times/pending' })).statusCode, 200) t.same((await agent.request({ origin, method: 'GET', path: '/times/pending' })).statusCode, 200) - const err = t.throws(() => agent.assertNoUnusedInterceptors({ tableFormatter })) + const err = t.throws(() => agent.assertNoPendingInterceptors({ tableFormatter })) t.same(err.message, ` 4 interceptors are pending: @@ -144,7 +144,7 @@ test('works when no interceptors are registered', t => { agent.disableNetConnect() t.same(agent.pendingInterceptors(), []) - t.doesNotThrow(() => agent.assertNoUnusedInterceptors()) + t.doesNotThrow(() => agent.assertNoPendingInterceptors()) }) test('works when all interceptors are pending', async t => { @@ -160,7 +160,7 @@ test('works when all interceptors are pending', async t => { t.same((await agent.request({ origin, method: 'GET', path: '/persistent' })).statusCode, 200) t.same(agent.pendingInterceptors(), []) - t.doesNotThrow(() => agent.assertNoUnusedInterceptors()) + t.doesNotThrow(() => agent.assertNoPendingInterceptors()) }) test('defaults to rendering output with terminal color when process.env.CI is unset', t => { @@ -171,7 +171,7 @@ test('defaults to rendering output with terminal color when process.env.CI is un delete process.env.CI const err = t.throws( - () => mockAgentWithOneInterceptor().assertNoUnusedInterceptors()) + () => mockAgentWithOneInterceptor().assertNoPendingInterceptors()) t.same(err.message, ` 1 interceptor is pending: diff --git a/test/types/mock-agent.test-d.ts b/test/types/mock-agent.test-d.ts index 3f13e3df36d..14f10a7550e 100644 --- a/test/types/mock-agent.test-d.ts +++ b/test/types/mock-agent.test-d.ts @@ -70,5 +70,5 @@ expectAssignable(new MockAgent({})) properties?: readonly string[] ): string; } - }) => void>(agent.assertNoUnusedInterceptors) + }) => void>(agent.assertNoPendingInterceptors) } diff --git a/types/mock-agent.d.ts b/types/mock-agent.d.ts index 98dffe09d19..3e3d867a20c 100644 --- a/types/mock-agent.d.ts +++ b/types/mock-agent.d.ts @@ -28,7 +28,7 @@ declare class MockAgent