Skip to content

Commit

Permalink
test: Clarify that cleanAll removes persistent mocks (#1647)
Browse files Browse the repository at this point in the history
Closes #1042
  • Loading branch information
paulmelnikow committed Aug 6, 2019
1 parent e661d0d commit bf1d7d6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -1007,7 +1007,7 @@ const scope = nock('http://example.com')

Note that while a persisted scope will always intercept the requests, it is considered "done" after the first interception.

If you want to stop persisting a persistent nock you can call `persist(false)`:
If you want to stop persisting an individual persisted mock you can call `persist(false)`:

```js
const scope = nock('http://example.com')
Expand All @@ -1020,6 +1020,8 @@ const scope = nock('http://example.com')
scope.persist(false)
```

You can also use `nock.cleanAll()` which removes all mocks, including persistent mocks.

To specify an exact number of times that nock should repeat the response, use [.times()](#repeat-response-n-times).

### .pendingMocks()
Expand Down
15 changes: 15 additions & 0 deletions tests/test_nock_lifecycle.js
Expand Up @@ -61,6 +61,7 @@ test('(re-)activate after restore', async t => {
test('clean all works', async t => {
nock('http://example.test')
.get('/')
.twice()
.reply()

await got('http://example.test/')
Expand Down Expand Up @@ -90,6 +91,20 @@ test('cleanAll should remove pending mocks from all scopes', t => {
t.end()
})

test('cleanAll removes persistent mocks', async t => {
nock('http://example.test')
.persist()
.get('/')
.reply()

nock.cleanAll()

await t.rejects(got('http://example.test/'), {
name: 'RequestError',
code: 'ENOTFOUND',
})
})

test('is done works', async t => {
nock('http://example.test')
.get('/')
Expand Down

0 comments on commit bf1d7d6

Please sign in to comment.