How do I unit test keystonejs models? How do I unit test keystonejs models? mongoose mongoose

How do I unit test keystonejs models?


There aren't any official examples of implementing unit testing for KeystoneJS sites yet, but there wouldn't be anything stopping you from writing tests with a framework like mocha, the way you would in any other node.js app.

You'd want to initialise Keystone, register your models, then connect to the database and execute tests without starting the web server. Something like this:

./tests.js

var keystone = require('keystone');keystone.init({    'name': 'Your Project'});keystone.import('models');keystone.mongoose.connect('localhost', 'your-database');keystone.mongoose.connection.on('open', function() {    // Run tests here    // Use keystone.list('Key') to access Lists and execute queries    // as you would in your main application});

then run tests.js, or make it an npm / grunt / etc. script.

Keep an eye on issue #216 for an integrated testing framework.