Skip to content

Commit

Permalink
fix: remove duplicates from activeMocks() and pendingMocks() (#2356)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbargiel committed Feb 17, 2024
1 parent 8bab28d commit 7e957b3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/intercept.js
Expand Up @@ -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() {
Expand Down
16 changes: 16 additions & 0 deletions tests/got/test_nock_lifecycle.js
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 7e957b3

Please sign in to comment.