【发布时间】:2023-03-21 12:20:01
【问题描述】:
我正在为节点代码编写单元测试用例,我需要将虚拟对象与实际结果进行比较。
为了比较,我在一个文件中写了一些虚拟 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: []
}}
我不知道这个错误是怎么回事
我已经设置了业力,我正在使用 mocha 和 chai 编写测试用例
任何帮助将不胜感激。
【问题讨论】:
-
如果您打印
result和expectedJSON,您得到正确的 JSON 吗?你知道错误是在instance.parseResponse还是assert抛出的? -
@DrakaSAN 我已经编写了测试用例来检查它们是否是在 instance.parseResponse 抛出的任何错误并且成功
-
你是和 WebPack 同时使用 Babel 吗?搜索该错误代码时似乎有很多结果。 example
-
我使用的是 webpack 但不是 babel
-
您是否导入了
json-loader? Seems to be a common error too
标签: node.js unit-testing webpack mocha.js karma-mocha