For AI agents: the complete documentation index is available at https://rstest.rs/zh/llms.txt, the full documentation bundle is available at https://rstest.rs/zh/llms-full.txt, and this page is available as Markdown at https://rstest.rs/zh/config/test/chai-config.md.
close
  • 简体中文
  • chaiConfig

    • 类型:
    type ChaiConfig = {
      /**
       * @default true
       */
      showDiff?: boolean;
      /**
       * @default 40
       */
      truncateThreshold?: number;
    };
    • 默认值: undefined

    自定义 Chai config。

    truncateThreshold

    • 类型: number
    • 默认值: 40

    断言失败时对象或数组的最大显示字符数。超出该阈值的内容会被截断。

    rstest.config.ts
    import { defineConfig } from '@rstest/core';
    
    export default defineConfig({
      chaiConfig: {
        truncateThreshold: 100, // 最多显示 100 个字符
      },
    });

    使用默认值 40 时,较长的数组或对象会被截断:

    AssertionError: expected [ 1, 2, [ 3, [ 4 ], ... ] ] to strictly equal
    [ 1, 2, [ 3 ] ]

    增大阈值后可以完整输出结构:

    AssertionError: expected [ 1, 2, [ 3, [ 4 ], { a: 1, length: 1 } ] ] to strictly equal
    [ 1, 2, [ 3 ] ]

    showDiff

    • 类型: boolean
    • 默认值: true

    是否在断言失败时显示期望值与实际值的差异。

    rstest.config.ts
    import { defineConfig } from '@rstest/core';
    
    export default defineConfig({
      chaiConfig: {
        showDiff: false, // 隐藏差异输出
      },
    });

    默认情况下,Rstest 会在断言失败时输出差异:

    AssertionError: expected { a: 1, b: 2 } to deeply equal { a: 1, b: 3 }
      + expected
      - actual
    
      {
        "a": 1
    +   "b": 3
    -   "b": 2
      }

    设置 showDiff: false 后,Rstest 只输出纯文本断言消息:

    AssertionError: expected { a: 1, b: 2 } to deeply equal { a: 1, b: 3 }