Skip to content

Commit

Permalink
docs(readme): Documentation Update for activate, isActive, restore me…
Browse files Browse the repository at this point in the history
…thods. (#1002)
  • Loading branch information
rash805115 authored and gr2m committed Oct 22, 2017
1 parent bd38736 commit f22dcc3
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion README.md
Expand Up @@ -56,8 +56,10 @@ For instance, if a module performs HTTP requests to a CouchDB server or makes HT
* [.persist()](#persist)
* [.pendingMocks()](#pendingmocks)
* [.activeMocks()](#activemocks)
* [.isActive()](#isactive)
- [Logging](#logging)
- [Restoring](#restoring)
- [Activating](#activating)
- [Turning Nock Off (experimental!)](#turning-nock-off-experimental)
- [Enable/Disable real HTTP request](#enabledisable-real-http-request)
- [Recording](#recording)
Expand Down Expand Up @@ -957,6 +959,17 @@ It is also available in the global scope:
console.error('active mocks: %j', nock.activeMocks());
```

## .isActive()

Your tests may sometimes want to deactivate the nock interceptor.
Once deactivated, nock needs to be re-activated to work.
You can check if nock interceptor is active or not by using `nock.isActive()`.
Sample:

```js
if (!nock.isActive()) nock.activate()
```

# Logging

Nock can log matches if you pass in a log function like this:
Expand All @@ -974,7 +987,19 @@ You can restore the HTTP interceptor to the normal unmocked behaviour by calling
```js
nock.restore();
```
**note**: restore does not clear the interceptor list. Use [nock.cleanAll()](#cleanall) if you expect the interceptor list to be empty.
**note 1**: restore does not clear the interceptor list. Use [nock.cleanAll()](#cleanall) if you expect the interceptor list to be empty.

**note 2**: restore will also remove the http interceptor itself. You need to run [nock.activate()](#activating) to re-activate the http interceptor. Without re-activation, nock will not intercept any calls.

# Activating

Only for cases where nock has been deactivated using [nock.restore()](#restoring), you can reactivate the HTTP interceptor to start intercepting HTTP calls using:

```js
nock.activate();
```

**note**: To check if nock HTTP interceptor is active or deactive, use [nock.isActive()](#isactive).

# Turning Nock Off (experimental!)

Expand Down

0 comments on commit f22dcc3

Please sign in to comment.