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