我一直在使用一個Web應用程序:使用磁帶/ ES6單元測試測試AMD模塊?
- ES5
- RequireJS
- 下劃線
- 骨幹
- jQuery的
我已經嘗試設置採用了全新的單元測試套件:
- ES6
- 磁帶
- Babel6
我的AMD模塊的應用程序/ UTIL/stringUtil.js:
define([], function() {
'use strict';
return {
isBlank: function(str) {
return _.isUndefined(str) || _.isNull(str) || _.isString(str) && str.trim().length === 0;
}
};
});
我在tapeTest.js單元測試:
import test from 'tape';
import sortUtil from 'app/util/stringUtil';
test('Testing stringUtil', (assert) => {
assert.ok(stringUtil.isBlank(' ')),
'Should be blank');
assert.end();
});
我的.babelrc:
{
"presets": ["es2015"]
}
我跑用膠帶測試:
tape -r babel-register tapeTest.js
我得到以下錯誤:
app/util/stringUtil.js:1
(function (exports, require, module, __filename, __dirname) { define([], function() {
^
ReferenceError: define is not defined
at Object.<anonymous> (stringUtil.js:1:23)
at Module._compile (module.js:434:26)
at loader (node_modules/babel-register/lib/node.js:126:5)
at Object.require.extensions.(anonymous function) [as .js] (node_modules/babel-register/lib/node.js:136:7)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (tapeTest.js:7:17)
at Module._compile (module.js:434:26)
我猜帶不承認AMD模塊?我能以某種方式解決這個問題嗎也許將AMD模塊轉儲到CommonJS模塊或其他東西?