Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript MongoClient在cucumberjs测试中未返回数据_Javascript_Node.js_Mongodb_Cucumber - Fatal编程技术网

Javascript MongoClient在cucumberjs测试中未返回数据

Javascript MongoClient在cucumberjs测试中未返回数据,javascript,node.js,mongodb,cucumber,Javascript,Node.js,Mongodb,Cucumber,我已经用几种不同的方法把它分开了。查找发生在删除之后,而查找从未找到任何内容。如果我注释掉this.accounts.remove…则查找有效。如果我把移除线留在那里,它不会。我对cucumberjs、mongo客户端和node的理解表明,这个发现应该是可行的 我甚至尝试过将remove/find序列移动到它自己的文件中,它在那里工作。似乎只有当我在cucumber中运行它时,序列才会失败。我怀疑是因为cucumber加载文件的方式,但我不确定 有人能帮我想一想如何让它工作吗 World.js:

我已经用几种不同的方法把它分开了。查找发生在删除之后,而查找从未找到任何内容。如果我注释掉
this.accounts.remove…
则查找有效。如果我把移除线留在那里,它不会。我对cucumberjs、mongo客户端和node的理解表明,这个发现应该是可行的

我甚至尝试过将remove/find序列移动到它自己的文件中,它在那里工作。似乎只有当我在cucumber中运行它时,序列才会失败。我怀疑是因为cucumber加载文件的方式,但我不确定

有人能帮我想一想如何让它工作吗

World.js:

var db = new Db('FlashCards', new Server('localhost', 27017));

db.open(function(err, opened) {
  if (err) {
    console.log("error opening: ", err);
    done(err);
  }
 db = opened;
});

var {
  defineSupportCode
} = require('cucumber');

function CustomWorld() {

  this.db = db;
 this.accounts = db.collection('accounts');
hooks.js:

Before(function(result, done) {
  //comment this out, and leave a done(), it works!!!!
  this.accounts.remove(function(error, result){
    if( error) {
      console.log("Error cleaning the database: ", error);
      done(error);
    }
    done();
  })
});
用户_steps.js:

Then('I will be registered', function(done) {
  let world = this;
  this.accounts.find({
    username: world.user.username
  }).toArray(
    function(err, accounts) {
      if (err) {
        console.log("Error retrieveing data: ", err);
        done(err);
      }
      console.log("Accounts found: ", accounts);
      expect(accounts).to.be.ok;
      expect(accounts.length).to.be.equal(1);
      done();
   });
});
创新:

cucumber-js --compiler es6:babel-core/register

删除方法中缺少要删除的项。我假设要删除的项目是


this.accounts.remove(函数(错误,结果){

您缺少一个要删除的参数。该参数是要删除的查询。我假设,删除查询是{username:world.user.username}

var qry={username:world.user.username}; 请尝试以下操作:

Before(function(result, done) { //comment this out, and leave a done(), it works!!!!
    var qry={username: world.user.username};
     this.accounts.remove(qry, function(error, result){ 
     if( error) { 
               console.log("Error cleaning the database: ", error);
               done(error);
       } 
      done(); 
       }) });

很抱歉,我不太清楚删除操作是否按预期进行。是之后的发现失败了。我将其清除。