【发布时间】:2017-04-21 09:30:50
【问题描述】:
我是摩卡的新手。当我从terminal 运行时,我的以下脚本有效。但是,当我从 testrunner.html 运行时没有结果。检查时,似乎是因为var xl = require('./excel');。如果我评论这个声明,它会起作用。我怎样才能使这项工作?我需要为我的脚本导入自定义模块。
更新了 test.js 以合并 RequireJS
- 发布更改:适用于浏览器和终端
module1.js
if(typeof define !== 'undefined')
{
define([], function() {
return {
get: function() {
return get();
}
};
});
}
else if(typeof exports !== 'undefined') {
module.exports = {
get: function(){
return get();
}
};
}
function get(){
return "hello node world";
}
test.js
if(typeof requirejs == 'undefined') {var requirejs = require('requirejs');}
if(typeof chai == 'undefined') {var chai = require('chai');}
requirejs.config({
baseUrl: '.',
paths: {
},
nodeRequire: require
});
describe("RequireTest()", function(){
var module1;
before(function(done){
requirejs(['./module1'],
function(_module) {
console.log('before fired');
module1 = _module;
if(typeof requirejs == 'undefined') {mocha.run();}
done();
});
});
it('test case: ', function(){
console.log(module1.get());
chai.expect(1+1).to.equal(2);
});
});
testrunner.html (sn-p)
<div id="mocha"></div>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/chai/chai.js"></script>
<script src="../node_modules/requirejs/require.js"></script>
<script>mocha.setup('bdd')</script>
<script src="./test.js"></script>
<script>mocha.run();</script>
【问题讨论】:
标签: mocha.js