node.js - How to test the Node js application with mocha-phantomjs -


i need test node js apllication mocha-phantomjs.i have tried below code test app i'm getting error 'referenceerror: can't find variable: require'.how resolve this.

test.html

<html> <head>     <title> tests </title>     <link rel="stylesheet" href="./node_modules/mocha/mocha.css" /> </head> <body>     <div id="mocha"></div>     <script src="../node_modules/mocha/mocha.js"></script>     <script src="../node_modules/should/lib/should.js"></script>      <script>         mocha.ui('bdd');         mocha.reporter('html');         </script>    <script src="test.js"></script>     <script>         if (window.mochaphantomjs) { mochaphantomjs.run(); }         else { mocha.run(); }     </script> </body> </html> 

test.js

 var module=require('../lib/requiredmodule');  var should = require('chai').should();  describe('testing',function(){     it('save data',function(){          module.save(content,function(err,res){            should.not.exist(err);          });     });   }); 

while running html file mocha-phantomjs test/test.html i'm getting error

      referenceerror: can't find variable: require 

so, think problem running tests via test runner runs them if client side. thus, not able find native node modules (like require). can try loading require.js in directly. or, use

    <script src="../node_modules/chai/chai.js"></script>     <script>         mocha.ui('bdd');          mocha.reporter('html');         var should = chai.should; // give access chai should.     </script> 

so not need require src to. again, think of doing client side.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -