我如何testingkeystonejs模型?

有什么办法可以运行testingkeystonejs也打一个testing或真正的MongoDB实例吗?

如果类似于Django的方式,那将会很好。

对于KeystoneJS站点没有任何官方的unit testing例子,但是不会有任何东西阻止你使用像mocha这样的框架来编写testing,就像你在其他node.js应用程序中那样。

您需要初始化Keystone,注册模型,然后连接到数据库并在不启动Web服务器的情况下执行testing。 像这样的东西:

./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 }); 

然后运行tests.js,或者使其成为npm / grunt /等脚本。

密切关注第216号课题的综合testing框架。