我需要使用mocha-phantomjs.测试我的Node js应用程序。我尝试了下面的代码来测试应用程序,但我得到的错误是'ReferenceError:Can not找到变量:require'.How解决这个问题。如何使用mocha-phantomjs测试Node js应用程序
的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);
});
});
});
当运行HTML文件作为摩卡phantomjs测试/ test.html的我得到错误的
ReferenceError: Can't find variable: require
浏览器不需要它的API,phantomjs和mocha-phantomjs不会为你介绍它。 – 2013-05-14 14:03:51