Skip to content

Commit 7e957b3

Browse files
authored
fix: remove duplicates from activeMocks() and pendingMocks() (#2356)
1 parent 8bab28d commit 7e957b3

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

lib/intercept.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ function interceptorScopes() {
350350
const nestedInterceptors = Object.values(allInterceptors).map(
351351
i => i.interceptors,
352352
)
353-
return [].concat(...nestedInterceptors).map(i => i.scope)
353+
const scopes = new Set([].concat(...nestedInterceptors).map(i => i.scope))
354+
return [...scopes]
354355
}
355356

356357
function isDone() {

tests/got/test_nock_lifecycle.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,22 @@ describe('Nock lifecycle functions', () => {
163163
await got('http://example.test/')
164164
expect(nock.activeMocks()).to.be.empty()
165165
})
166+
167+
it("activeMocks doesn't return duplicate mocks", () => {
168+
nock('http://example.test')
169+
.get('/')
170+
.reply()
171+
.get('/second')
172+
.reply()
173+
.get('/third')
174+
.reply()
175+
176+
expect(nock.activeMocks()).to.deep.equal([
177+
'GET http://example.test:80/',
178+
'GET http://example.test:80/second',
179+
'GET http://example.test:80/third',
180+
])
181+
})
166182
})
167183

168184
describe('resetting nock catastrophically while a request is in progress', () => {

0 commit comments

Comments
 (0)