CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-jest-matcher-utils

A set of utility functions for expect and related packages

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

value-formatting.mddocs/

Value Formatting

Core functions for converting objects to formatted string representations with proper styling and whitespace handling for test output.

Capabilities

Stringify Function

Converts objects to string representation with formatting control for maximum readability in test output.

/**
 * Convert objects to string representation with formatting
 * @param object - Object to stringify
 * @param maxDepth - Maximum recursion depth (default: 10)
 * @param maxWidth - Maximum width for formatting (default: 10)
 * @returns Formatted string representation
 */
function stringify(
  object: unknown,
  maxDepth?: number,
  maxWidth?: number
): string;

Usage Examples:

import { stringify } from "jest-matcher-utils";

// Basic object stringification
const user = { name: "Alice", age: 25, active: true };
const result = stringify(user);
// Result: '{"name": "Alice", "age": 25, "active": true}'

// Control depth and width
const nested = { a: { b: { c: { d: "deep" } } } };
const shallow = stringify(nested, 2);
// Limits recursion depth to prevent overly verbose output

// Large objects are automatically truncated
const large = { data: new Array(1000).fill("item") };
const compact = stringify(large, 10, 5);
// Automatically reduces depth/width to stay under length limits

Print Received

Formats received (actual) values with red color styling and trailing whitespace indicators.

/**
 * Format received values with red color and whitespace indicators
 * @param object - Value to format as received
 * @returns Red-colored string with whitespace indicators
 */
function printReceived(object: unknown): string;

Usage Examples:

import { printReceived } from "jest-matcher-utils";

// Format actual values for error messages
const actual = { name: "Bob", age: 30 };
const formatted = printReceived(actual);
// Result: Red-colored '{"name": "Bob", "age": 30}' 

// Handles whitespace visualization
const withSpaces = "hello world   ";
const spaced = printReceived(withSpaces);
// Result: Red-colored 'hello world···' (shows trailing spaces)

Print Expected

Formats expected values with green color styling and trailing whitespace indicators.

/**
 * Format expected values with green color and whitespace indicators
 * @param value - Value to format as expected
 * @returns Green-colored string with whitespace indicators
 */
function printExpected(value: unknown): string;

Usage Examples:

import { printExpected } from "jest-matcher-utils";

// Format expected values for error messages
const expected = { name: "Alice", age: 25 };
const formatted = printExpected(expected);
// Result: Green-colored '{"name": "Alice", "age": 25}'

// Works with all data types
const expectedNumber = printExpected(42);
const expectedString = printExpected("hello");
const expectedArray = printExpected([1, 2, 3]);

Highlight Trailing Whitespace

Highlights trailing whitespace in text using inverse color formatting.

/**
 * Highlight trailing whitespace in text with inverse colors
 * @param text - Input text to process
 * @returns Text with highlighted trailing whitespace
 */
function highlightTrailingWhitespace(text: string): string;

Usage Examples:

import { highlightTrailingWhitespace } from "jest-matcher-utils";

// Highlight invisible trailing spaces
const text = "Line 1   \nLine 2  \nLine 3";
const highlighted = highlightTrailingWhitespace(text);
// Result: 'Line 1[INVERSE]   [/INVERSE]\nLine 2[INVERSE]  [/INVERSE]\nLine 3'

// Useful for debugging string comparison issues
const userInput = "username ";
const processed = highlightTrailingWhitespace(userInput);
// Makes trailing space visible in test output

Print With Type

Prints a value along with its type information for debugging complex type issues.

/**
 * Print value with its type information
 * @param name - Name/label for the value
 * @param value - Value to print
 * @param print - Function to format the value
 * @returns Formatted output with type info
 */
function printWithType<T>(
  name: string,
  value: T,
  print: (value: T) => string
): string;

Usage Examples:

import { printWithType, printReceived } from "jest-matcher-utils";

// Show value with type for debugging
const mysterious = Symbol.for("test");
const result = printWithType("Received", mysterious, printReceived);
// Result: 'Received has type:  symbol\nReceived has value: Symbol(test)'

// Helpful for null/undefined debugging
const empty = null;
const nullResult = printWithType("Expected", empty, printReceived);
// Result: 'Expected has value: null'

// Works with any formatter function
const obj = { x: 1 };
const objResult = printWithType("Data", obj, (val) => JSON.stringify(val));
// Result: 'Data has type:  object\nData has value: {"x":1}'

docs

diff-generation.md

index.md

matcher-display.md

value-formatting.md

value-validation.md

tile.json