我有一个网络应用程序使用:
- ES5
- 要求JS
- 下划线
- 骨干
- jQuery
我尝试使用以下方法设置新的单元测试套件:
- ES6
- 胶带
- 通天塔6
我的 AMD 模块 app/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 模块之类的?