superagent-nock-patch
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -8,3 +8,2 @@ 'use strict'; | ||
exports.default = function (superagent) { | ||
// don't patch if superagent was patched already | ||
@@ -88,2 +87,5 @@ if (superagent._patchedBySuperagentMocker) { | ||
console.warn('This is an unmaintained fork of `superagent-nock`.'); | ||
console.warn('Please switch to using the upstream package at https://www.npmjs.com/package/superagent-nock'); | ||
var methodsMapping = { | ||
@@ -90,0 +92,0 @@ get: 'GET', |
{ | ||
"name": "superagent-nock-patch", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Mock superagent http requests", | ||
@@ -31,5 +31,3 @@ "repository": { | ||
"eslint-plugin-react": "^6.10.0" | ||
}, | ||
"dependencies": { | ||
} | ||
} |
@@ -0,5 +1,16 @@ | ||
# Warning - unmaintained package. | ||
This is an unmaintained fork of `superagent-nock`. I made this fork to fix a | ||
single issue in upstream, but a | ||
[PR](https://github.com/lowik/superagent-nock/pull/4) fixing the isssue has been | ||
merged and this repo is no longer necessary. | ||
Please switch to using the upstream package | ||
`[superagent-nock](https://www.npmjs.com/package/superagent-nock)` | ||
# superagent-nock | ||
Very simple mock of superagent http requests for testing purpose (from Node.js or the browser). | ||
Inspired by superagent-mocker, superagent-mock and nock. | ||
Very simple mock of superagent http requests for testing purpose (from Node.js | ||
or the browser). Inspired by superagent-mocker, superagent-mock and nock. | ||
Used for testing React components with Redux and Observable. | ||
@@ -10,2 +21,3 @@ | ||
## Setup | ||
```js | ||
@@ -20,14 +32,21 @@ import request from 'superagent'; | ||
Define the base url | ||
```js | ||
nock('http://localhost') | ||
nock('http://localhost'); | ||
``` | ||
The url to mock | ||
```js | ||
nock.get('/events/10') | ||
nock.get('/events/10'); | ||
``` | ||
The result to return | ||
```js | ||
nock.reply(httpStatus, responseBody) | ||
nock.reply(httpStatus, responseBody); | ||
``` | ||
or specify a function | ||
```js | ||
@@ -37,8 +56,10 @@ nock.reply(function() { | ||
status: 200, | ||
result: responseBody | ||
result: responseBody, | ||
}; | ||
}) | ||
}); | ||
``` | ||
Then, when you do a get request on the url, the callback return the specified result | ||
Then, when you do a get request on the url, the callback return the specified | ||
result | ||
```js | ||
@@ -48,3 +69,3 @@ nock('http://localhost') | ||
.reply(200, { | ||
id: 10, | ||
id: 10, | ||
title: 'My event' | ||
@@ -63,2 +84,3 @@ }); | ||
You can chain your urls to mock: | ||
```js | ||
@@ -68,6 +90,6 @@ nock('http://localhost') | ||
.reply(200, { | ||
id: 10, | ||
title: 'My event' | ||
id: 10, | ||
title: 'My event', | ||
}) | ||
.get('/members/1') | ||
.get('/members/1') | ||
.reply(404); | ||
@@ -79,2 +101,3 @@ ``` | ||
You should probably install it in devDependencies (-D) | ||
```sh | ||
@@ -86,3 +109,2 @@ $ npm i -D superagent-nock | ||
nock.delay | ||
nock.query | ||
nock.delay nock.query |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7347
136
103