Unable to delete mongoose collection within Cucumber-JS Step

124 views Asked by At

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?

0

There are 0 answers