I was using Mocha to test my Nodejs app with a test database. In order to reset the DB before each test I had the following code, which worked perfectly:
process.env.NODE_ENV = 'test';
var knex = require('../db/knex');
describe("Add Item", function() {
beforeEach(function(done) {
knex.migrate.rollback()
.then(function() {
knex.migrate.latest()
.then(function() {
return knex.seed.run()
.then(function() {
done();
});
});
});
});
...
I've since switched from mocha to mocha-casperjs for my integration tests, and now the knex migrations won't run. I'm given this error message with the exact same before each hook:
undefined is not an object (evaluating 'knex.migrate.rollback')
phantomjs://platform/new-item.js:12:17
value@phantomjs://platform/mocha-casperjs.js:114:20
callFnAsync@phantomjs://platform/mocha.js:4314:12
run@phantomjs://platform/mocha.js:4266:18
next@phantomjs://platform/mocha.js:4630:13
phantomjs://platform/mocha.js:4652:9
timeslice@phantomjs://platform/mocha.js:12620:27