Comparing version 3.2.0 to 3.3.0
@@ -8,3 +8,3 @@ 'use strict'; | ||
const assert = require('assert'); | ||
const isFunction = is.function; | ||
const supertestRequest = require('supertest'); | ||
@@ -106,5 +106,5 @@ module.exports = { | ||
const origin = obj[name]; | ||
assert(isFunction(origin), `property ${name} in original object must be function`); | ||
assert(is.function(origin), `property ${name} in original object must be function`); | ||
if (isFunction(data)) { | ||
if (is.function(data)) { | ||
const fn = data; | ||
@@ -133,3 +133,3 @@ if (is.generatorFunction(origin) && !is.generatorFunction(fn)) { | ||
if (isFunction(origin)) { | ||
if (is.function(origin)) { | ||
mm(obj, name, () => { | ||
@@ -371,2 +371,12 @@ if (data instanceof Error) { | ||
}, | ||
/** | ||
* http request helper | ||
* @method App#httpRequest | ||
* @return {SupertestRequest} req - supertest request | ||
* @see https://github.com/visionmedia/supertest | ||
*/ | ||
httpRequest() { | ||
return supertestRequest(this.callback()); | ||
}, | ||
}; | ||
@@ -373,0 +383,0 @@ |
3.3.0 / 2017-04-15 | ||
================== | ||
* feat: add app.httpRequest() test helper (#38) | ||
3.2.0 / 2017-03-14 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -12,2 +12,3 @@ 'use strict'; | ||
const awaitEvent = require('await-event'); | ||
const supertestRequest = require('supertest'); | ||
@@ -46,3 +47,2 @@ const formatOptions = require('./format_options'); | ||
class ClusterApplication extends Coffee { | ||
/** | ||
@@ -182,2 +182,5 @@ * @constructor | ||
httpRequest() { | ||
return supertestRequest(this.callback()); | ||
} | ||
} | ||
@@ -184,0 +187,0 @@ |
{ | ||
"name": "egg-mock", | ||
"version": "3.2.0", | ||
"version": "3.3.0", | ||
"eggPlugin": { | ||
@@ -36,3 +36,4 @@ "name": "egg-mock" | ||
"mm": "^2.1.0", | ||
"rimraf": "^2.6.1" | ||
"rimraf": "^2.6.1", | ||
"supertest": "^3.0.0" | ||
}, | ||
@@ -48,4 +49,3 @@ "devDependencies": { | ||
"pedding": "^1.1.0", | ||
"sdk-base": "^3.0.1", | ||
"supertest": "^3.0.0" | ||
"sdk-base": "^3.0.1" | ||
}, | ||
@@ -52,0 +52,0 @@ "ci": { |
@@ -23,3 +23,3 @@ # egg-mock | ||
Mock library for Egg testing. | ||
Mock library for testing Egg applications, plugins and custom Egg frameworks with ease. `egg-mock` inherits all APIs from [node_modules/mm](https://github.com/node-modules/mm), offering more flexibility. | ||
@@ -42,3 +42,2 @@ ## Install | ||
const mm = require('egg-mock'); | ||
const request = require('supertest'); | ||
@@ -56,5 +55,5 @@ describe('some test', () => { | ||
it('should request /', () => { | ||
return request(app.callback()) | ||
.get('/') | ||
.expect(200); | ||
return app.httpRequest() | ||
.get('/') | ||
.expect(200); | ||
}); | ||
@@ -165,5 +164,5 @@ }); | ||
it('some test', () => { | ||
return request(app.callback()) | ||
.get('/config') | ||
.expect(200) | ||
return app.httpRequest() | ||
.get('/config') | ||
.expect(200) | ||
}); | ||
@@ -210,3 +209,3 @@ }); | ||
### mm.restore | ||
### mm.restore() | ||
@@ -274,2 +273,17 @@ restore all mock data, e.g. `afterEach(mm.restore)` | ||
### app.httpRequest() | ||
Request current app http server. | ||
```js | ||
it('should work', () => { | ||
return app.httpRequest() | ||
.get('/') | ||
.expect('hello world') | ||
.expect(200); | ||
}); | ||
``` | ||
See [supertest](https://github.com/visionmedia/supertest) to get more APIs. | ||
### app.mockContext(options) | ||
@@ -335,5 +349,6 @@ | ||
app.mockCsrf(); | ||
request(app.callback()) | ||
.post('/login') | ||
.expect(302, done); | ||
return app.httpRequest() | ||
.post('/login') | ||
.expect(302); | ||
``` | ||
@@ -355,3 +370,3 @@ | ||
// follow options.dataType to convert | ||
data: 'mock taobao', | ||
data: 'mock egg', | ||
}); | ||
@@ -363,5 +378,5 @@ // app.mockHttpclient('https://eggjs.org', 'get', mockResponse); // mock get | ||
request(app.callback()) | ||
return app.httpRequest() | ||
.post('/') | ||
.expect('mock taobao', done); | ||
.expect('mock egg'); | ||
``` | ||
@@ -368,0 +383,0 @@ |
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
38493
9
914
382
13
+ Addedsupertest@^3.0.0
+ Addedasynckit@0.4.0(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcomponent-emitter@1.3.1(transitive)
+ Addedcookiejar@2.1.4(transitive)
+ Addeddebug@3.2.7(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedform-data@2.5.2(transitive)
+ Addedformidable@1.2.6(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedmethods@1.1.2(transitive)
+ Addedmime@1.6.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedqs@6.13.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.25.2.1(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedsuperagent@3.8.3(transitive)
+ Addedsupertest@3.4.2(transitive)
+ Addedutil-deprecate@1.0.2(transitive)