Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to test express app headless with Mocha and Zombie.js

How to test express app headless with Mocha and Zombie.js

Problem

I am trying to run some Mocha/Zombie.js tests on my new node.js (express) app.

Now I want to do it without having to restart the node app.

Now, I have a working test, something like this:

var assert=require('assert')
    , Browser = require("zombie")
    ;

var browser = new Browser();
browser.site = "http://domain.com";
browser.silent = false;

describe('Home page', function(){
    describe ('Page title', function(){
        it('should open a home page', function(done){
            browser.visit('/').
            then(function(done){
                assert.equal(browser.text("title"), "My page title");
                done();
            }).fail(function(err){
                done(err);
            });
        });
    });
});

So, when the test fails, I change the page title, reload the app and then re-run the test so it passes.

I know I can do something like:

var server = require('../server');
var browser = new Browser();

I just don't know how, and I can't see from Mocha and Zombie example pages.

How do I tell the Browser.visit to visit the server and not the real deployed web page?

Problem courtesy of: Zlatko

Solution

As I was suggested on chat here, I am using Node-supervisor - a supervisor for node apps, to which I say what to watch and restart the app automatically when it changes.

Solution courtesy of: Zlatko

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

How to test express app headless with Mocha and Zombie.js

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×