在严格的断言模式中,非严格方法的行为类似于其对应的严格方法。 例如,[assert.deepEqual()] 的行为类似于 [assert.deepStrictEqual()]。

    在严格的断言模式中,对象的错误消息会显示差异。 在传统的断言模式中,对象的错误消息会显示对象(通常是截断的)。

    使用严格的断言模式:

    1. const assert = require('assert').strict;

    错误差异的示例:

    1. const assert = require('assert').strict;
    2. assert.deepEqual([[[1, 2, 3]], 4, 5], [[[1, 2, '3']], 4, 5]);
    3. // AssertionError: Expected inputs to be strictly deep-equal:
    4. // + actual - expected ... Lines skipped
    5. //
    6. // [
    7. // [
    8. // ...
    9. // 2,
    10. // + 3
    11. // - '3'
    12. // ],
    13. // ...
    14. // 5
    15. // ]

    若要禁用颜色,则使用 NO_COLORNODE_DISABLE_COLORS 环境变量。 这也会禁用 REPL 中的颜色。 有关终端环境中的颜色支持,详见 tty 的 [getColorDepth()][_tty_writestream_getcolordepth] 文档。