【问题标题】:Error: need to load appropriate loader while writing unit test case错误:在编写单元测试用例时需要加载适当的加载器
【发布时间】: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 编写测试用例

任何帮助将不胜感激。

【问题讨论】:

  • 如果您打印 resultexpectedJSON,您得到正确的 JSON 吗?你知道错误是在instance.parseResponse还是assert抛出的?
  • @DrakaSAN 我已经编写了测试用例来检查它们是否是在 instance.parseResponse 抛出的任何错误并且成功
  • 你是和 WebPack 同时使用 Babel 吗?搜索该错误代码时似乎有很多结果。 example
  • 我使用的是 webpack 但不是 babel
  • 您是否导入了json-loaderSeems to be a common error too

标签: node.js unit-testing webpack mocha.js karma-mocha


【解决方案1】:

我的猜测是你必须在 webpack 中导入 json-loader,这似乎是查看所有 googme 搜索结果的常见错误。

【讨论】:

  • 我导入了它,还为 webpack 添加了 polyfill,但仍然出现同样的错误
猜你喜欢
  • 2018-01-08
  • 1970-01-01
  • 1970-01-01
  • 2015-09-04
  • 2018-05-07
  • 1970-01-01
  • 1970-01-01
  • 2021-02-08
  • 2019-09-24
相关资源
最近更新 更多