cheatsheets/nock.md

28 lines
382 B
Markdown
Raw Permalink Normal View History

2014-02-25 11:32:14 +01:00
---
title: Nock
2015-11-24 06:02:17 +01:00
category: JavaScript libraries
2014-02-25 11:32:14 +01:00
---
### Nock
2018-02-19 17:10:17 +01:00
```js
scope = nock('http://foo.com')
scope = nock('http://foo.com', { allowUnmocked: true })
```
2014-02-25 11:32:14 +01:00
2018-02-19 17:10:17 +01:00
```js
nock('http://foo.com')
.get('/user')
.reply(200, { id: 1234 })
```
2014-02-25 11:32:14 +01:00
### Filtering
2018-02-19 17:10:17 +01:00
```js
nock('http://foo.com')
.filteringPath(/[&\?]token=[^&]*/g, '')
.get('/user')
2014-02-25 11:32:14 +01:00
2018-02-19 17:10:17 +01:00
// catches "/user?token=..." as well
```