I fairly new to node and mocha and brand new to Zombie. I am trying to write some functional tests for my application. It is built using node/express. And when you try to log into a page (the dashboard in my example) it will redirect you to the login. Upon logging in, it will send you back to the requested page. On the dashboard, there is a button to click that will take you to an offer summary page. (These pages do use requirejs to load the necessary javascript)
I am trying to test that scenario using Mocha and I am able to test the redirect to login and then the loading the original page. However, when I pressButton for the offerSummary I am getting the following error:
Error: Wrong document
at Object.core.Node.insertBefore (..zombie/node_modules/jsdom/lib/jsdom/level1/core.js:501:13)
at Object.<anonymous> (../zombie/node_modules/jsdom/lib/jsdom/level2/events.js:314:20)
at Object.proto.(anonymous function) [as insertBefore] (../node_modules/zombie/node_modules/jsdom/lib/jsdom/utils.js:21:26)
at Object.core.Node.appendChild (../zombie/node_modules/jsdom/lib/jsdom/level1/core.js:621:17)
at Function.l.load (/javascripts/requirejs/require.2.1.2.min.js:33:148)
at Object.j.load (/javascripts/requirejs/require.2.1.2.min.js:28:351)
Here is my mocha test
describe.only('dashboard', function() {
var browser;
beforeEach(function(done){
var routeToVisit = "/dashboard";
browser = new Browser();
browser.on("error", function(err) {
done(err);
});
browser.visit(startingUrl + routeToVisit, function(){
browser.location.pathname.should.equal("/login.html");
browser.fill("#username", "abc");
browser.fill("#password", "abc");
browser.pressButton("#login", function (res){
browser.location.pathname.should.equal(routeToVisit);
done();
});
});
});
it('offers dashboards should redirect correctly', function(done){
should.exist(browser.query("#dbOffers"));
should.exist(browser.query("#dbOffersValue"));
should.exist(browser.query("#dbOffersText"));
browser.pressButton("#dbOffers", function(res){
browser.location.pathname.should.equal("/offerSummary");
done();
});
});
});
Any help would be appreciated.