3.3.14 • Published 4 years ago

egg-mongoose-mock v3.3.14

Weekly downloads
44
License
-
Repository
github
Last release
4 years ago

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

3.3.13

4 years ago

3.3.14

4 years ago

3.3.12

4 years ago

3.3.10

4 years ago

3.3.9

4 years ago

3.3.8

4 years ago

3.3.7

4 years ago

3.3.6

4 years ago

3.3.5

4 years ago

3.3.4

4 years ago

3.3.3

4 years ago

3.3.2

4 years ago

3.3.1

4 years ago

3.3.0

4 years ago