Provides additional operations for the configuration instance that are not part of the configuration properties.
Defines a custom message to display when a circular reference is detected in a value.
The default is a function that returns the string "[
Defiines the default assertion failure message to display if no message is provided.
Defines the default fatal message to display if no message is provided.
Options for configuring value formatting.
These options allow you to customize how values are formatted in assertion error messages. Custom formatters can be added via the format manager (see IConfigInst.formatMgr). Custom formatters are checked in order: current context formatters first, then parent context formatters, and finally default formatters. This allows you to provide specialized formatting for certain value types that takes precedence over inherited and default formatting.
Additionally, you can control post-processing of the formatted output using IFormatterOptions.finalize and IFormatterOptions.finalizeFn to escape ANSI codes, wrap output, or apply other transformations.
import { assertConfig } from '@nevware21/tripwire';
import { eFormatResult } from '@nevware21/tripwire';
import { escapeAnsi, gray, replaceAnsi } from '@nevware21/chromacon';
// Example 1: Custom formatters with default ANSI escaping
assertConfig.format = {
finalize: true // Enable default escapeAnsi
};
assertConfig.formatMgr.addFormatter({
name: "stringFormatter",
value: (ctx, value) => {
if (typeof value === 'string') {
return { res: FormatResult.Ok, val: `'${value}'` };
}
return { res: FormatResult.Skip };
}
});
// Example 2: Custom formatters with custom finalization
assertConfig.format = {
finalize: true,
finalizeFn: (value) => replaceAnsi(value, (match) => gray(escapeAnsi(match)))
};
assertConfig.formatMgr.addFormatter({
name: "arrayFormatter",
value: (ctx, value) => {
if (Array.isArray(value)) {
return { res: FormatResult.Ok, val: `[${value.length} items]` };
}
return { res: FormatResult.Skip };
}
});
Identifies if the current context is in full-stack mode, which will include the full stack trace in the error message if an assertion fails.
Identifies if the current context is verbose mode, which will include additional information in the execution context and any resulting assertion failures.
Indicates whether to show the difference between expected and actual values in the error message.
Instance of the configuration options
Since
0.1.5
Remarks
The IConfigInst interface represents an instance of configuration options for the assertion library. It provides access to the current configuration settings, including verbosity, stack trace options, default messages, formatting options, circular reference handling, and diff display settings.