How to test Front-end of the node application using mocha and phantom.js

841 views Asked by At

I made a single page application using backbone(client-side), node(back-end). All the templating part was happening at client-side. I am using node for fetching,updating and setting data into database.

Until now, I used to test application manually, so I decided to test application with mocha,chai,phantom and mocha-phantomjs. Why I choose these libraries, because I can run test cases in terminal so later I can implement Continuous Integration.

So I installed all the libraries using npm.I started my node server,I can access my application through browser usinglocalhost:3004(node server redirecting to my index.html file,which is places under public folder. Inside this file I didn't mention any mocha corresponding files.).Now I want to test my application,without open my application I can't able to test so I am planning to open through browser.I written the following code and saved as InitialPageLoad.js.

var mocha=require('mocha'),
chai=require('chai'),
mochaPhantomJS=require('mochaPhantomJS');
mocha.ui('bdd'); 
mochaPhantomJS.run();
var page = require('webpage').create();
page.open('localhost:3004', function() {
    console.log(document.getElementById("login-name"));
});

My index.html looks like the following way.

<html>
<head>
    <title> Tests </title>
</head>
<body>
   //written my application corresponding templates and loading corresponding developer fiels
</body>
</html>

I switch to my project folder and then invoke the following code.

mocha-phantomjs public/testCases/InitialPageLoad.js

It's returning the following error

Failed to start mocha: Init timeout

First What I am doing, is it right or not.

0

There are 0 answers