
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
mongoose-fixture-loader
Advanced tools
A promise fixture loader for Mongoose.
Load a single object
loadFixture(UserModel, userObject);
Load an array of objects
loadFixture(UserModel, arrayOfUserObjects);
Load a sequence of objects
loadFixture(UserModel, userObject)
.then((userInstance) => {
loadFixture(BookModel, bookObjectRelatedToUserObject)
});
Load objects in parallel
Promise.all([
loadFixture(UserModel, userObject),
loadFixture(CatModel, catObject),
loadFixture(DogModel, dogObject)
]);
npm install --save mongoose-fixture-loader
Assume you have a user model file src/models/user-model.js
as the following.
const mongoose = require('mongoose');
const UserSchema = new mongoose.Schema({
firstName: { type: String, required: true },
lastName: {type: String, required: true },
email: { type: String },
created: { type: Date, default: Date.now }
});
module.exports = mongoose.model('User', UserSchema);
Create a fixture file test/fixtures/user.js
to export a JSON object,
module.exports = {
firstName: 'John',
lastName: 'Doe',
email: 'john.doe@test.com'
};
or an array of JSON object.
module.exports = [
{
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
, load the fixture into MongoDB.
const loadFixture = require('mongoose-fixture-loader');
const UserModel = require('../src/models/user-model.js');
const user = require('./fixtures/user.js');
describe('a test suite', () => {
before((done) => {
loadFixture(UserModel, user)
.then((userInst) => {
done();
})
.catch((err) => {
done(err);
});
});
});
Enjoy testing!
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
Copyright (c) 2016 Supasate Choochaisri
Licensed under the Apache License.
FAQs
A promise fixture loader for Mongoose
We found that mongoose-fixture-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.