我正在使用 nodeunit 进行 node.js 服务器端代码测试。这是我的代码片段。我没有添加所有代码,但您可以查看错误参考。
在方法中的 bwlow 代码中,test adding a project
我将项目添加到 mongodb,然后在保存后从服务器获得响应后,我将新添加的 _id 分配给 me.projectToUpdate['_id']。
我的问题是我无法在test build a project
测试用例中获取 me.projectToUpdate['_id'] 的值。
exports.group = {
setUp: function(callback) {
var me = this;
me.projectToSave = {};
me.projectToUpdate = {};
},
"test for smoke": function(test) {
test.ok(null == null);
test.done();
},
"test adding a project": function(test) {
var me = this;
me.queue.call("Adding project to DB", function(callbacks) {
// Here I have defined the me.projectToSave object with all fields
project.save(me.projectToSave, callbacks.add(function(call, callReturn) {
//Here I am assigning the project id to me.projectToUpdate object
me.projectToUpdate['_id'] = String(callReturn._id);
}));
});
me.queue.process(test);
},
"test build a project": function(test) {
var me = this;
me.queue.call("Let start the build process", function(callbacks) {
var command = me.config['xmlDeploy'] + ' ' + me.config['options'];
// Here I need the me.projectToUpdate['_id'] to send to server
build.start({project: me.projectToUpdate['_id']}, callbacks.add(function() {
}));
});
me.queue.process(test);
}
};