egg-mongoose-mock
TypeScript icon, indicating that this package has built-in type declarations

3.3.14 • Public • Published

egg-mongoose-mock

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Egg's mongoose plugin for unit testing.

Install

$ npm i egg-mongoose-mock --save-dev

Configuration

Change {app_root}/config/plugin.unittest.js to enable egg-mongoose-mock plugin:

exports.mongoose = {
  enable: false,
  package: 'egg-mongoose',
};
exports.mongooseMock = {
  enable: true,
  package: 'egg-mongoose-mock',
};

Simple connection

Config

// {app_root}/config/config.unittest.js
exports.mongoose = {
  client: {
    plugins: []
  }
};
exports.mongooseMock = {
  options: {
    autoReconnect: true,
    useNewUrlParser: true,
    useFindAndModify: false,
    useCreateIndex: true,
    useUnifiedTopology: true,
  },
};

Example

// {app_root}/app/model/user.js
module.exports = app => {
  const mongoose = app.mongoose;
  const Schema = mongoose.Schema;
 
  const UserSchema = new Schema({
    userName: { type: String  },
    password: { type: String  },
  });
 
  return mongoose.model('User', UserSchema);
}
 
// {app_root}/app/controller/user.js
exports.index = function* (ctx) {
  ctx.body = yield ctx.model.User.find({});
}

Default config

see config/config.default.js for more detail.

Questions & Suggestions

Please open an issue here.

Contribution

If you are a contributor, follow CONTRIBUTING.

License

MIT

Package Sidebar

Install

npm i egg-mongoose-mock

Weekly Downloads

5

Version

3.3.14

License

none

Unpacked Size

11 kB

Total Files

10

Last publish

Collaborators

  • ewinds