egg-mongoose-mock
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:
exportsmongoose = enable: false package: 'egg-mongoose';exportsmongooseMock = enable: true package: 'egg-mongoose-mock';
Simple connection
Config
// {app_root}/config/config.unittest.jsexportsmongoose = client: plugins: ;exportsmongooseMock = options: autoReconnect: true useNewUrlParser: true useFindAndModify: false useCreateIndex: true useUnifiedTopology: true ;
Example
// {app_root}/app/model/user.jsmodule { const mongoose = appmongoose; const Schema = mongooseSchema; const UserSchema = userName: type: String password: type: String ; return mongoose;} // {app_root}/app/controller/user.jsexports { ctxbody = ctxmodelUser;}
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.