Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

egg-mock

Package Overview
Dependencies
Maintainers
5
Versions
132
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-mock - npm Package Compare versions

Comparing version 3.2.0 to 3.3.0

18

app/extend/application.js

@@ -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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc