diff --git a/lib/intercept.js b/lib/intercept.js index cf266d5a5..bcc1319ce 100644 --- a/lib/intercept.js +++ b/lib/intercept.js @@ -350,7 +350,8 @@ function interceptorScopes() { const nestedInterceptors = Object.values(allInterceptors).map( i => i.interceptors, ) - return [].concat(...nestedInterceptors).map(i => i.scope) + const scopes = new Set([].concat(...nestedInterceptors).map(i => i.scope)) + return [...scopes] } function isDone() { diff --git a/tests/got/test_nock_lifecycle.js b/tests/got/test_nock_lifecycle.js index 92a07efe8..622f3076b 100644 --- a/tests/got/test_nock_lifecycle.js +++ b/tests/got/test_nock_lifecycle.js @@ -163,6 +163,22 @@ describe('Nock lifecycle functions', () => { await got('http://example.test/') expect(nock.activeMocks()).to.be.empty() }) + + it("activeMocks doesn't return duplicate mocks", () => { + nock('http://example.test') + .get('/') + .reply() + .get('/second') + .reply() + .get('/third') + .reply() + + expect(nock.activeMocks()).to.deep.equal([ + 'GET http://example.test:80/', + 'GET http://example.test:80/second', + 'GET http://example.test:80/third', + ]) + }) }) describe('resetting nock catastrophically while a request is in progress', () => {