菜单
开源软件

配置

Chai 暴露了一些选项来更改库配置。

配置选项默认值描述
truncateMsgThreshold300检查消息长度将被截断到此值。
truncateVariableThreshold100插值到检查消息中的变量将截断到此长度。这可以防止在检查名称非常长时出错,特别是在 `aggregateChecks` 为 `false` 时。
aggregateCheckstrue实际值不会被插值到检查消息中。对于 1 次迭代的测试禁用此项。
logFailuresfalse当检查失败时,会打印调试消息。
JavaScript
import http from 'k6/http';
import chai, { describe, expect } from 'https://jslib.k6.io/k6chaijs/4.3.4.3/index.js';

// individual variables should be up to 20 chars after rendering.
chai.config.truncateVariableThreshold = 20;

// whole check() message must be below 300 chars.
chai.config.truncateMsgThreshold = 300;

// the variable values (resp.status) are inserted into the check message - useful for debugging or tests with 1 iteration
chai.config.aggregateChecks = false;

// when the check fails, WARN messages with variables are printed. Useful for debugging.
chai.config.logFailures = true;

export default function testSuite() {
  describe('Testing bad assertion.', () => {
    const response = http.get('https://quickpizza.grafana.com');

    expect(response.body).to.have.lengthOf.at.least(100);
  });
}

结果为

bash
█ Testing bad assertion.
  ✓ expected '<!DOCTYPE html>\n<html lang="en">\n<hea...' to have property 'length'
  ✓ expected '<!DOCTYPE html>\n<html lang="en">\n<hea...' to have a length at least 100 got 2611