Mongoose Fixture Loader
A promise fixture loader for Mongoose.
-
Load a single object
; -
Load an array of objects
; -
Load a sequence of objects
; -
Load objects in parallel
Promiseall;
Installation
npm install --save mongoose-fixture-loader
Usage
-
Assume you have a user model file
src/models/user-model.js
as the following.const mongoose = ;const UserSchema =firstName: type: String required: truelastName: type: String required: trueemail: type: Stringcreated: type: Date default: Datenow;moduleexports = mongoose; -
Create a fixture file
test/fixtures/user.js
to export a JSON object,moduleexports =firstName: 'John'lastName: 'Doe'email: 'john.doe@test.com';or an array of JSON object.
moduleexports =firstName: 'John'lastName: 'Doe'email: 'john.doe@test.com'firstName: 'Alice'lastName: 'Bob'email: 'alice.bob@test.com'; -
In your test file
test/index-test.js
, you can load and test your fixture.const expect = expect;const mongoose = ;const loadFixture = ;const UserModel = ;const user = ;// Mongoose default promise is deprecatedmongoosePromise = globalPromise;; -
Enjoy testing!
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
License
Copyright (c) 2016 Supasate Choochaisri
Licensed under the Apache License.