Saturday 10 June 2017

MongoClient not returning data in cucumberjs test

I've taken this apart several different ways. If I comment out the this.accounts.remove... it works. If I leave it in there it doesn't. My understanding of cucumberjs, mongo client and node indicates that it should work.

Can someone help me figure out how to get this working?

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();
  })
});

user_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();
   });
});

Inovcation:

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



via Jim Barrows

No comments:

Post a Comment