繁体   English   中英

使用 mocha/chai 如何让它显示跳过的行?

[英]With mocha/chai how can i make it show lines skipped?

我有一个失败的单元测试,它正在比较两个大的 arrays,而 mocha 的 output 被部分跳过。

         "Qualifying/Commissions/Amount"
         "Qualifying/Other/Amount"
         "Qualifying/Overtime/Amount"
         "Qualifying/Total/Amount"
      -  "Factors/De/ ... Lines skipped
      +  "Factors/De/Base/Amount"
      +  "Factors/De/Bo ... Lines skipped

我如何获得更多被跳过的行? Pytest 有一个-v选项用于详细。

这是调用的结果

expect(actual).to.deep.equal(expected)

其中 actual 和 expected 是 big ol' arrays 的字符串。

版本:
“摩卡”:“^ 9.0.3”,
"sinon-chai": "^3.5.0",
“柴”:“〜4.1”,

这个比较麻烦,我也遇到过。

长话短说

go 到 node_modules/mocha/lib/reporters/base.js: 193 change const diffSize = 2048; 到更大的。

细节

他们限制行大小的原因是因为这个问题: https://github.com/mochajs/mocha/issues/3675

他们用这个 PR 解决了问题: https://github.com/mochajs/mocha/pull/4638

相关代码是:

 const diffSize = 2048;
    if (actual.length > diffSize) {
      actual = actual.substring(0, diffSize) + ' ... Lines skipped';
    }
    if (expected.length > diffSize) {
      expected = expected.substring(0, diffSize) + ' ... Lines skipped';
    }

因此,您需要将 diffSize 修改为更大的值。 也许仅限本地开发人员,如果您想在其他环境中使用它,请尝试一些补丁挂钩。

如果你看到这个,你需要将 mocha 更新到至少v9.2.1然后你可以使用--reporter-option maxDiffSize=0

从文档:

New in v9.2.1

By default strings are truncated to 8192 characters before generating a diff. This is to prevent performance problems with large strings.

It can however make the output harder to interpret when comparing large strings. Therefore it is possible to configure this value using --reporter-option maxDiffSize=[number].

A value of 0 indicates no limit, default is 8192 characters.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM