0

I'm using Cucumber-JS to write some BDD features and Mongoose to reset a database for each scenario.

I'm setting up a background task, generating the step for it and changing the callback.pending() to callback() which passes.

Feature: x
  Background: Clear person collection
    Given that I have an empty person collection
...

and my step code:

...
this.Given(/^that I have an empty person collection$/, function (callback) {
    callback();
});
...

I add a require statement to my mongoose schema and then wrap the callback in this:

var Product = require("../models/product);
...
this.Given(/^that I have an empty person collection$/, function (callback) {
    Product.remove(function(err){
        callback();
    });
});
...

this is the product.js file

var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var ProductSchema = new Schema({
    name: String,
    price: String,
    description: String
});

module.exports = mongoose.model('Product', ProductSchema);

And when I run cucumber-js is just terminates. When I go back and remove the remove function, it runs fine again.

I've even tried running it like this:

...
this.Given(/^that I have an empty person collection$/, function (callback) {
    Product.remove().exec(callback);
});
...

Any ideas what is causing this behaviour?

chris31389
  • 8,414
  • 7
  • 55
  • 66
  • I think `Product.remove` is failing before even remove() is called and cucumber is not reporting the exception back. May be add a try, catch and check if you see any exception? – nilesh Jun 22 '15 at 18:41
  • Hi @nilesh I tried wrapping it in a try catch and it still just terminates with no exception thrown :s – chris31389 Jun 25 '15 at 20:11

0 Answers0