From a3d5892a13a0b2274072ac339161ddc581e03926 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Tue, 29 Apr 2025 12:25:04 +0000 Subject: [PATCH] fix(readme): Update usage examples and full matcher reference in README --- changelog.md | 7 +++ readme.md | 94 +++++++++++++++++++++++++++++++++++++++- ts/00_commitinfo_data.ts | 2 +- 3 files changed, 100 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index fa72e9f..c91adfe 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2025-04-29 - 2.2.1 - fix(readme) +Update usage examples and full matcher reference in README + +- Removed deprecated 'expectAsync' from import example +- Fixed formatting in documentation +- Added comprehensive full matcher reference section + ## 2025-04-29 - 2.2.0 - feat(generics) Improve assertion and matcher type definitions by adding execution mode generics for better async/sync support diff --git a/readme.md b/readme.md index 15297af..142d1a0 100644 --- a/readme.md +++ b/readme.md @@ -17,10 +17,10 @@ This will add `@push.rocks/smartexpect` to your project's dependencies. Make sur ### Getting Started -First, import `@push.rocks/smartexpect` into your TypeScript file: + First, import `@push.rocks/smartexpect` into your TypeScript file: ```typescript -import { expect, expectAsync } from '@push.rocks/smartexpect'; +import { expect } from '@push.rocks/smartexpect'; ``` ### Synchronous Expectations @@ -254,6 +254,96 @@ expect(4).not.toBeOdd(); - Matcher functions receive the value under test (`received`) plus any arguments. - Must return an object with `pass` (boolean) and `message` (string or function) for failure messages. +### Full Matcher Reference + +Below is a comprehensive list of all matchers and utility functions available in `@push.rocks/smartexpect`. + +#### Modifiers and Utilities +- `.not` Negates the next matcher in the chain. +- `.resolves` Switches to async mode, expecting the promise to resolve. +- `.rejects` Switches to async mode, expecting the promise to reject. +- `.withTimeout(ms)` Sets a timeout (in milliseconds) for async assertions. +- `.timeout(ms)` (deprecated) Alias for `.withTimeout(ms)`. +- `.property(name)` Drill into a property of an object. +- `.arrayItem(index)` Drill into an array element by index. +- `.log()` Logs the current value and assertion path for debugging. +- `.setFailMessage(message)` Override the failure message for the current assertion. +- `.setSuccessMessage(message)` Override the success message for the current assertion. +- `.customAssertion(fn, message)` Execute a custom assertion function with a message. +- `expect.extend(matchers)` Register custom matchers globally. +- `expect.any(constructor)` Matcher for values that are instances of the given constructor. +- `expect.anything()` Matcher for any defined value (not null or undefined). + +#### Basic Matchers +- `.toEqual(expected)` Deep (or strict for primitives) equality. +- `.toBeTrue()` Value is strictly `true`. +- `.toBeFalse()` Value is strictly `false`. +- `.toBeTruthy()` Value is truthy. +- `.toBeFalsy()` Value is falsy. +- `.toBeNull()` Value is `null`. +- `.toBeUndefined()` Value is `undefined`. +- `.toBeNullOrUndefined()` Value is `null` or `undefined`. +- `.toBeDefined()` Value is not `undefined`. + +#### Number Matchers +- `.toBeGreaterThan(value)` +- `.toBeLessThan(value)` +- `.toBeGreaterThanOrEqual(value)` +- `.toBeLessThanOrEqual(value)` +- `.toBeCloseTo(value, precision?)` +- `.toEqual(value)` Strict equality for numbers. +- `.toBeNaN()` +- `.toBeFinite()` +- `.toBeWithinRange(min, max)` + +#### String Matchers +- `.toStartWith(prefix)` +- `.toEndWith(suffix)` +- `.toInclude(substring)` +- `.toMatch(regex)` +- `.toBeOneOf(arrayOfValues)` +- `.toHaveLength(length)` +- `.toBeEmpty()` Alias for empty string. + +#### Array Matchers +- `.toBeArray()` +- `.toHaveLength(length)` +- `.toContain(value)` +- `.toContainEqual(value)` +- `.toContainAll(arrayOfValues)` +- `.toExclude(value)` +- `.toBeEmptyArray()` +- `.toBeEmpty()` Alias for empty array. +- `.toHaveLengthGreaterThan(length)` +- `.toHaveLengthLessThan(length)` + +#### Object Matchers +- `.toEqual(expected)` Deep equality for objects. +- `.toMatchObject(partialObject)` Partial deep matching (supports `expect.any` and `expect.anything`). +- `.toBeInstanceOf(constructor)` +- `.toHaveProperty(propertyName, value?)` +- `.toHaveDeepProperty(pathArray)` +- `.toHaveOwnProperty(propertyName, value?)` +- `.toBeNull()` +- `.toBeUndefined()` +- `.toBeNullOrUndefined()` + +#### Function Matchers +- `.toThrow(expectedError?)` +- `.toThrowErrorMatching(regex)` +- `.toThrowErrorWithMessage(message)` + +#### Date Matchers +- `.toBeDate()` +- `.toBeBeforeDate(date)` +- `.toBeAfterDate(date)` + +#### Type Matchers +- `.toBeTypeofString()` +- `.toBeTypeofNumber()` +- `.toBeTypeofBoolean()` +- `.toBeTypeOf(typeName)` + ## Best Practices - **Human-readable assertions**: The fluent API is designed to create tests that read like natural language sentences. diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 7dddf82..93314b5 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartexpect', - version: '2.2.0', + version: '2.2.1', description: 'A testing library to manage expectations in code, offering both synchronous and asynchronous assertion methods.' }