项目作者: ewinds

项目描述 :
Egg's mongoose plugin for unit testing.
高级语言: JavaScript
项目地址: git://github.com/ewinds/egg-mongoose-mock.git
创建时间: 2020-10-27T09:23:46Z
项目社区:https://github.com/ewinds/egg-mongoose-mock

开源协议:MIT License

下载


egg-mongoose-mock

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

Egg’s mongoose plugin for unit testing.

Install

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

Configuration

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

  1. exports.mongoose = {
  2. enable: false,
  3. package: 'egg-mongoose',
  4. };
  5. exports.mongooseMock = {
  6. enable: true,
  7. package: 'egg-mongoose-mock',
  8. };

Simple connection

Config

  1. // {app_root}/config/config.unittest.js
  2. exports.mongoose = {
  3. client: {
  4. plugins: []
  5. }
  6. };
  7. exports.mongooseMock = {
  8. options: {
  9. autoReconnect: true,
  10. useNewUrlParser: true,
  11. useFindAndModify: false,
  12. useCreateIndex: true,
  13. useUnifiedTopology: true,
  14. },
  15. };

Example

  1. // {app_root}/app/model/user.js
  2. module.exports = app => {
  3. const mongoose = app.mongoose;
  4. const Schema = mongoose.Schema;
  5. const UserSchema = new Schema({
  6. userName: { type: String },
  7. password: { type: String },
  8. });
  9. return mongoose.model('User', UserSchema);
  10. }
  11. // {app_root}/app/controller/user.js
  12. exports.index = function* (ctx) {
  13. ctx.body = yield ctx.model.User.find({});
  14. }

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