对整个 node.js 社区来说相当新,我在我的第一个应用程序上进行单元测试时遇到了问题。问题是它们通过了,但它们实际上从未在回调中运行断言。据我了解,猫鼬(我用来与 MongoDB 对话的库)使用回调来处理它的 API。在我的誓言测试中,这些回调似乎没有被触发。一个例子:
vows = require 'vows'
assert = require 'assert'
mongoose = require 'mongoose'
ProjectSchema = new Schema
name: String
Project = mongoose.model 'Project', ProjectSchema
mongoose.connect('mongodb://localhost/testdb');
projectBatch = vows.describe('Project').addBatch
'model attributes':
topic: ()->
new Project()
'should have a name field': (topic)->
topic.name = "some name"
topic.save
console.log "this gets executed just fine"
Project.findById topic.id, (error, project)->
console.log "THIS LINE NEVER RUNS!"
assert.equal "some name", project.name
projectBatch.export module
关于我在这里做错了什么的任何想法?