2013-11-03 21 views
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 

作爲輸出我有文本,而不是錯誤。爲什麼當我做測試時,我得到了錯誤,並像往常一樣執行不?

+0

在測試中啓用i18日誌記錄:'DEBUG = i18n:* mocha -g {失敗的測試名稱}'。如果日誌沒有足夠的幫助,則創建一個小型測試用例來重現問題,並在此處發佈完整的源代碼和i18n日誌。 –

回答

0

這是一個老問題,但爲他人着想,這裏是爲我工作的解決方案:

極有可能是區域設置目錄的位置。 檢查在i18n.configure中配置的locate目錄的位置是否相對。

您在執行節點時以及執行摩卡測試時從不同位置運行,因此i18n無法找到區域設置文件夾。

相關問題