2
我正在使用摩卡测试框架来测试我的应用程序和翻译我正在使用来自mashpie的i18n。
在我validation.js文件,我需要国际化模块和使用国际化.__功能像摩卡测试i18n TypeError:无法读取未定义的属性'text50'
console.log(i18n.__('text50'));
在我的测试文件validation.test.js我需要测试validation.js。然后我用摩卡进行测试,因为我得到了结果。
Running "mochaTest:test" (mochaTest) task
>> Mocha exploded!
>> TypeError: Cannot read property 'text50' of undefined
>> at translate (/Volumes/Develop/townspeech/node_modules/i18n/i18n.js:355:23)
>> at Object.i18nTranslate [as __] (/Volumes/Develop/townspeech/node_modules/i18n/i18n.js:96:11)
>> at Object.<anonymous> (/Volumes/Develop/townspeech/server/libs/validation.js:24:18)
>> at Module._compile (module.js:456:26)
>> at Object.Module._extensions..js (module.js:474:10)
>> at Module.load (module.js:356:32)
>> at Function.Module._load (module.js:312:12)
>> at Module.require (module.js:364:17)
>> at require (module.js:380:17)
>> at Object.<anonymous> (/Volumes/Develop/townspeech/server/controllers/new_password.js:10:18)
Warning: Task "mochaTest:test" failed. Used --force, continuing.
但是当我尝试
node validation.js
作为输出我有文本,而不是错误。为什么当我做测试时,我得到了错误,并像往常一样执行不?
在测试中启用i18日志记录:'DEBUG = i18n:* mocha -g {失败的测试名称}'。如果日志没有足够的帮助,则创建一个小型测试用例来重现问题,并在此处发布完整的源代码和i18n日志。 –