Мне нужно протестировать мой Node js apllication с помощью mocha-phantomjs.I попробовал приведенный ниже код для тестирования приложения, но я получаю ошибку как «ReferenceError: Can not find variable: require'.Как решить эту проблему.Как протестировать приложение Node js с mocha-phantomjs
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 не представляют его для вас. –