0
刚刚开始接触摩卡并不能为我的生活弄清楚为什么它认为Helper
未定义在指定的线下/列:摩卡不能创建我的函数的一个实例
test.js
var assert = require('assert'),
helper = require('../src/js/helper.js');
describe('helper', function() {
describe('#parseValue', function() {
it('should return number of minutes for a properly formatted string', function() {
assert.equal(1501, (new Helper()).parseValue('1d 1h 1m', 'when'));
^^^^^^^^^^^^
});
});
});
helper.js
(function(exports) {
'use strict';
function Helper(opts) {
this.opts = opts || {};
/**
* Parse a value based on its type and return a sortable version of the original value
*
* @param {string} val input value
* @param {string} type type of input value
* @returns {mixed} sortable value corresponding to the input value
*/
this.parseValue = function(val, type) {
switch (type) {
case 'when':
var d = val.match(/\d+(?=d)/),
h = val.match(/\d+(?=h)/),
m = val.match(/\d+(?=m)/);
if (m)
m = parseInt(m, 10);
if (h)
m += parseInt(h, 10) * 60;
if (d)
m += parseInt(d, 10) * 1440;
val = m;
break;
default:
break;
}
return val;
};
}
exports.helper = Helper;
})(this);
我写了一个快速测试在没有摩卡的浏览器中,以确保我的helper.js功能是可访问的,它工作正常,所以我真的很茫然。我通过从我的目录中的命令行调用mocha
直接在我的服务器上运行此操作。
谢谢。你的编辑很有帮助。 :) – tenub