断言错误 - 输出有噪音.如何仅显示断言

AssertionError - output is noisy. How do I show only Assertion

本文关键字:断言 何仅 显示 噪音 错误 输出      更新时间:2023-09-26

从入门运行实习单元测试示例时,当我更改 Hello 单元脚本并运行它以使其断言时,它似乎显示比我需要的更多细节(嘈杂)。 此输出是否正确? 有没有办法只显示断言错误行,也许显示发生此断言的文件/行?

unit_hello.js:

define([
    'intern!object',
    'intern/chai!assert',
    'app/hello'
], function (registerSuite, assert, hello) {
registerSuite({
    name: 'hello',
    greet: function () {
        assert.strictEqual(hello.greet('Name'), 'Hello, Name!',
            'hello.greet should return a greeting for the person name in the first argument');
        assert.strictEqual(hello.greet(), 'Hello, World!',
            'hello.greet with no arguments should return a greeting to "world"');
        }
    });
});

输出:

user@pcname:~/intern_example$ ./node_modules/.bin/intern-client config=tests/intern_unit
FAIL: main - hello - greet (1ms)
AssertionError: hello.greet with no arguments should return a greeting to "world":  expected 'Hello, world!' to equal 'Hello, World!'
  at Function.assert.strictEqual  <node_modules/intern/node_modules/chai/chai.js:2487:32>
  at Test.registerSuite.greet [as test]  <tests/unit/unit_hello.js:13:20>
  at Test.run  <node_modules/intern/lib/Test.js:169:19>
  at <node_modules/intern/lib/Suite.js:237:13>
  at signalListener  <node_modules/intern/node_modules/dojo/Deferred.js:37:21>
  at Promise.then.promise.then  <node_modules/intern/node_modules/dojo/Deferred.js:258:5>
  at runTest  <node_modules/intern/lib/Suite.js:236:46>
  at <node_modules/intern/lib/Suite.js:249:7>
  at process._tickCallback  <node.js:419:13>
1/1 tests failed
1/1 tests failed

您可以编写和加载自己的自定义报告器,以输出您想要或不想要的任何信息。标准报告器将始终提供完整的堆栈跟踪。

有一个 filterErrorStack 配置选项,它告诉 Intern 通过删除非应用程序代码来清理错误堆栈跟踪。

它从版本 3.4(发布于 18.11.2016)开始。