2016-09-30 15 views
0

我正在爲節點代碼編寫單元測試用例,我需要將虛擬對象與實際結果進行比較。錯誤:在寫單元測試用例時需要加載適當的加載程序

爲了比較,我在文件中寫了一些虛擬的JSON數據和我最終得到錯誤You may need to load appropraite loaders to handle this file type

代碼:

it('comparing structures',()=>{ 
    var result = instance.parseResponse(input,esResponse); 
    assert.deepEqual(result, expectedJSON, "Two objects can be the same in value"); 
}); 

JSON:

var expectedJSON ={ 
DateMetric { 
    aggregate: Aggregate { 
     total: 0, 
     average: null, 
     count: 0, 
     min: null, 
     max: null 
    }, 
    startDate: Fri Apr 01 2016 05: 30: 00 GMT + 0530(India Standard Time), 
    weeks: [] 
}} 

我不知道是什麼這個錯誤全是關於

我有業力設置,我正在寫測試案件使用摩卡和柴

任何幫助,將不勝感激。

+0

如果你打印'result'和'expectedJSON',你會得到正確的JSON嗎?你知道錯誤是拋出'instance.parseResponse'還是'assert'? – DrakaSAN

+0

@DrakaSAN我已經編寫了測試用例來檢查它們是否在instance.parseResponse引發的任何錯誤,並且它是成功的 –

+0

您是否在與WebPack同時使用Babel?搜索該錯誤代碼時似乎有很多結果。 [示例](http://stackoverflow.com/questions/33469929/you-may-need-an-appropriate-loader-to-handle-this-file-type-with-webpack-and-b) – DrakaSAN

回答

1

我的猜測是你必須導入json-loader在webpack,這似乎是一個常見的錯誤,看到所有googme搜索結果。

+0

我導入它,並且還爲webpack添加了polyfill,但仍然出現相同的錯誤 –

相關問題