From a91e6e7817b63ffbc07a1b7f783d420d8acc631c Mon Sep 17 00:00:00 2001 From: Keegan Witt Date: Wed, 21 May 2025 23:20:04 -0400 Subject: [PATCH] Automate creating index.d.ts --- .gitignore | 1 + package.json | 8 +- clean.js => scripts/clean.js | 2 +- scripts/generate-types.ts | 141 +++ src/matchers/fail.ts | 6 + src/matchers/pass.ts | 6 + src/matchers/toBeAfter.ts | 4 + src/matchers/toBeAfterOrEqualTo.ts | 4 + src/matchers/toBeArray.ts | 11 +- src/matchers/toBeArrayOfSize.ts | 4 + src/matchers/toBeBefore.ts | 3 + src/matchers/toBeBeforeOrEqualTo.ts | 4 + src/matchers/toBeBetween.ts | 5 + src/matchers/toBeBoolean.ts | 3 + src/matchers/toBeDate.ts | 3 + src/matchers/toBeDateString.ts | 3 + src/matchers/toBeEmpty.ts | 3 + src/matchers/toBeEmptyObject.ts | 3 + src/matchers/toBeEven.ts | 3 + src/matchers/toBeExtensible.ts | 3 + src/matchers/toBeFalse.ts | 3 + src/matchers/toBeFinite.ts | 3 + src/matchers/toBeFrozen.ts | 3 + src/matchers/toBeFunction.ts | 3 + src/matchers/toBeHexadecimal.ts | 3 + src/matchers/toBeInRange.ts | 6 + src/matchers/toBeInteger.ts | 3 + src/matchers/toBeNaN.ts | 3 + src/matchers/toBeNegative.ts | 3 + src/matchers/toBeNil.ts | 3 + src/matchers/toBeNumber.ts | 3 + src/matchers/toBeObject.ts | 3 + src/matchers/toBeOdd.ts | 3 + src/matchers/toBeOneOf.ts | 4 + src/matchers/toBePositive.ts | 3 + src/matchers/toBeSealed.ts | 3 + src/matchers/toBeString.ts | 11 +- src/matchers/toBeSymbol.ts | 3 + src/matchers/toBeTrue.ts | 3 + src/matchers/toBeValidDate.ts | 3 + src/matchers/toBeWithin.ts | 6 + src/matchers/toChange.ts | 1 + src/matchers/toChangeBy.ts | 2 + src/matchers/toChangeTo.ts | 5 +- src/matchers/toContainAllEntries.ts | 5 + src/matchers/toContainAllKeys.ts | 4 + src/matchers/toContainAllValues.ts | 5 + src/matchers/toContainAnyEntries.ts | 5 + src/matchers/toContainAnyKeys.ts | 5 + src/matchers/toContainAnyValues.ts | 5 + src/matchers/toContainEntries.ts | 5 + src/matchers/toContainEntry.ts | 5 + src/matchers/toContainKey.ts | 5 + src/matchers/toContainKeys.ts | 5 + src/matchers/toContainValue.ts | 5 + src/matchers/toContainValues.ts | 5 + src/matchers/toEndWith.ts | 5 + src/matchers/toEqualCaseInsensitive.ts | 5 + src/matchers/toEqualIgnoringWhitespace.ts | 5 + src/matchers/toHaveBeenCalledAfter.ts | 8 + src/matchers/toHaveBeenCalledBefore.ts | 8 + .../toHaveBeenCalledExactlyOnceWith.ts | 3 + src/matchers/toHaveBeenCalledOnce.ts | 3 + src/matchers/toInclude.ts | 5 + src/matchers/toIncludeAllMembers.ts | 4 + src/matchers/toIncludeAllPartialMembers.ts | 4 + src/matchers/toIncludeAnyMembers.ts | 4 + src/matchers/toIncludeMultiple.ts | 5 + src/matchers/toIncludeRepeated.ts | 6 + src/matchers/toIncludeSameMembers.ts | 4 + src/matchers/toIncludeSamePartialMembers.ts | 4 + src/matchers/toPartiallyContain.ts | 4 + src/matchers/toReject.ts | 3 + src/matchers/toResolve.ts | 3 + src/matchers/toSatisfy.ts | 4 + src/matchers/toSatisfyAll.ts | 4 + src/matchers/toSatisfyAny.ts | 6 +- src/matchers/toStartWith.ts | 5 + src/matchers/toThrowWithMessage.ts | 6 + .../toIncludeSamePartialMembers.test.ts | 1 - tsconfig.json | 6 +- tsconfig.test.json | 3 +- types/index.d.ts | 942 ------------------ yarn.lock | 92 +- 84 files changed, 552 insertions(+), 965 deletions(-) rename clean.js => scripts/clean.js (73%) create mode 100644 scripts/generate-types.ts delete mode 100644 types/index.d.ts diff --git a/.gitignore b/.gitignore index d2ad8f84..558db529 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ coverage .vscode package-lock.json *tsbuildinfo +/types/index.d.ts diff --git a/package.json b/package.json index 0958cd3e..c8020ab5 100644 --- a/package.json +++ b/package.json @@ -3,24 +3,27 @@ "version": "5.0.3", "description": "Additional Jest matchers", "main": "dist/index.js", - "types": "types/index.d.ts", "files": [ "dist", "types/index.d.ts", "all.js" ], "scripts": { - "clean": "node clean.js", + "clean": "node scripts/clean.js", "prebuild": "yarn clean", "build": "tsc && tsc-alias", + "postbuild": "yarn generate-types", + "generate-types": "ts-node scripts/generate-types.ts", "lint": "eslint .", "lint:fix": "yarn lint --fix", "prepare": "husky", "prepublishOnly": "yarn build", "precommit": "lint-staged", + "pretest": "yarn generate-types", "test": "jest --color=true", "test:clearCache": "yarn test --clearCache", "test:updateSnapshot": "yarn test --updateSnapshot", + "pretest:coverage": "yarn generate-types", "test:coverage": "yarn test --coverage", "test:watch": "yarn test --watch", "typecheck": "tsc --noEmit", @@ -61,6 +64,7 @@ "lint-staged": "~15.5.0", "prettier": "^3.0.0", "ts-jest": "^29.0.0", + "ts-node": "^10.9.2", "tsc-alias": "^1.8.0", "typescript": "^5.0.0" }, diff --git a/clean.js b/scripts/clean.js similarity index 73% rename from clean.js rename to scripts/clean.js index 684edf92..1084b52c 100644 --- a/clean.js +++ b/scripts/clean.js @@ -1,6 +1,6 @@ const fs = require('fs'); const path = require('path'); -const distPath = path.join(__dirname, 'dist'); +const distPath = path.join(__dirname, '..', 'dist'); if (fs.existsSync(distPath)) { fs.rmSync(distPath, { recursive: true, force: true }); } diff --git a/scripts/generate-types.ts b/scripts/generate-types.ts new file mode 100644 index 00000000..1448410a --- /dev/null +++ b/scripts/generate-types.ts @@ -0,0 +1,141 @@ +import * as ts from 'typescript'; +import * as fs from 'fs'; +import * as path from 'path'; + +interface MatcherInfo { + name: string; + docComment: string; + parameters: { + name: string; + type: string; + optional?: boolean; + rest?: boolean; + }[]; + returnType: string; +} + +function extractMatcherInfo(sourceFile: ts.SourceFile): MatcherInfo[] { + const matchers: MatcherInfo[] = []; + ts.forEachChild(sourceFile, node => { + if (ts.isFunctionDeclaration(node) && node.name) { + const matcherName = node.name.text; + // Extract the full JSDoc block (not just tags) + let docComment = ''; + const jsDocs = (node as any).jsDoc; + if (jsDocs && jsDocs.length > 0 && jsDocs[0].comment) { + docComment = jsDocs[0].comment; + // If there are tags, add them as well + if (jsDocs[0].tags && jsDocs[0].tags.length > 0) { + const tags = jsDocs[0].tags.map((tag: any) => { + let tagLine = `@${tag.tagName.escapedText}`; + if (tag.typeExpression && tag.typeExpression.type) { + tagLine += ` {${tag.typeExpression.type.getText()}}`; + } + if (tag.name) tagLine += ` ${tag.name.escapedText}`; + if (tag.comment) tagLine += ` ${tag.comment}`; + return tagLine; + }); + docComment += '\n' + tags.join('\n'); + } + } + // Skip the first parameter (actual) as it's implicit in Jest matchers + const parameters = node.parameters.slice(1).map(param => { + const paramName = param.name.getText(sourceFile); + const paramType = param.type ? param.type.getText(sourceFile) : 'unknown'; + // Check if parameter is optional (has default value or is marked with ?) + const isOptional = param.initializer !== undefined || param.questionToken !== undefined; + // Check if parameter is a rest parameter + const isRest = param.dotDotDotToken !== undefined; + return { + name: paramName, + type: paramType, + optional: isOptional, + rest: isRest + }; + }); + const returnType = node.type ? node.type.getText(sourceFile) : 'unknown'; + matchers.push({ name: matcherName, docComment, parameters, returnType }); + } + }); + return matchers; +} + +function generateTypeDefinition(matcher: MatcherInfo): string { + // Split docComment into lines, trim, and wrap in JSDoc + let docBlock = ''; + if (matcher.docComment && matcher.docComment.trim().length > 0) { + const lines = matcher.docComment.split('\n').map(line => ` * ${line.trim()}`); + docBlock = [' /**', ...lines, ' */'].join('\n'); + } + const params = matcher.parameters.map(p => { + const prefix = p.rest ? '...' : ''; + const suffix = p.optional ? '?' : ''; + return `${prefix}${p.name}${suffix}: ${p.type}`; + }).join(', '); + + // Check if the function uses the E type parameter + const needsGenericE = matcher.parameters.some(p => p.type.includes('E')) || + matcher.returnType.includes('E'); + + // Add generic type parameter if needed + const genericParams = needsGenericE ? '' : ''; + + // Add two newlines after each method for clarity + return `\n${docBlock}\n ${matcher.name}${genericParams}(${params}): R;\n`; +} + +function generateTypeFile(matchers: MatcherInfo[]): string { + return `interface CustomMatchers extends Record {${matchers + .map(generateTypeDefinition) + .join('')} +} + +declare namespace jest { + interface Matchers {${matchers + .map(generateTypeDefinition) + .join('')} + } + + interface Expect extends CustomMatchers {} + interface InverseAsymmetricMatchers extends Expect {} +} + +declare module 'jest-extended' { + const matchers: CustomMatchers; + export = matchers; +}`; +} + +function main() { + const matchersDir = path.join(__dirname, '../src/matchers'); + const typesDir = path.join(__dirname, '../types'); + const outputFile = path.join(typesDir, 'index.d.ts'); + + // Read all matcher files + const matcherFiles = fs.readdirSync(matchersDir) + .filter(file => file.endsWith('.ts') && file !== 'index.ts'); + + const matchers: MatcherInfo[] = []; + + // Process each matcher file + for (const file of matcherFiles) { + const filePath = path.join(matchersDir, file); + const sourceFile = ts.createSourceFile( + filePath, + fs.readFileSync(filePath, 'utf8').replace(/\r/g, ''), + ts.ScriptTarget.Latest, + true + ); + + const matcherInfos = extractMatcherInfo(sourceFile); + matchers.push(...matcherInfos); + } + + // Generate and write type definitions + const typeDefinitions = generateTypeFile(matchers); + fs.mkdirSync(typesDir, { recursive: true }); + fs.writeFileSync(outputFile, typeDefinitions); + console.log(`Generated type definitions in ${outputFile}`); +} + +main(); \ No newline at end of file diff --git a/src/matchers/fail.ts b/src/matchers/fail.ts index 25e713d6..40bcb820 100644 --- a/src/matchers/fail.ts +++ b/src/matchers/fail.ts @@ -1,3 +1,9 @@ +/** + * Note: Currently unimplemented + * Failing assertion + * + * @param {String} message + */ export function fail(_: unknown, message: string) { return { pass: false, diff --git a/src/matchers/pass.ts b/src/matchers/pass.ts index e8c3c448..42046d60 100644 --- a/src/matchers/pass.ts +++ b/src/matchers/pass.ts @@ -1,3 +1,9 @@ +/** + * Note: Currently unimplemented + * Passing assertion + * + * @param {String} message + */ export function pass(_: unknown, message: string) { return { pass: true, diff --git a/src/matchers/toBeAfter.ts b/src/matchers/toBeAfter.ts index c0e68ae9..e50357c4 100644 --- a/src/matchers/toBeAfter.ts +++ b/src/matchers/toBeAfter.ts @@ -1,3 +1,7 @@ +/** + * Use `.toBeAfter` when checking if a date occurs after `date`. + * @param {Date} after + */ export function toBeAfter(actual: unknown, after: Date) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, matcherHint } = this.utils; diff --git a/src/matchers/toBeAfterOrEqualTo.ts b/src/matchers/toBeAfterOrEqualTo.ts index d197af7d..d4ad5c78 100644 --- a/src/matchers/toBeAfterOrEqualTo.ts +++ b/src/matchers/toBeAfterOrEqualTo.ts @@ -1,3 +1,7 @@ +/** + * Use `.toBeAfterOrEqualTo` when checking if a date equals to or occurs after `date`. + * @param {Date} date + */ export function toBeAfterOrEqualTo(actual: unknown, expected: Date) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, matcherHint } = this.utils; diff --git a/src/matchers/toBeArray.ts b/src/matchers/toBeArray.ts index 089cd83b..258f2536 100644 --- a/src/matchers/toBeArray.ts +++ b/src/matchers/toBeArray.ts @@ -1,8 +1,11 @@ -export function toBeArray(expected: unknown) { +/** + * Use `.toBeArray` when checking if a value is an `Array`. + */ +export function toBeArray(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { matcherHint, printReceived } = this.utils; - const pass = Array.isArray(expected); + const pass = Array.isArray(actual); return { pass, @@ -11,10 +14,10 @@ export function toBeArray(expected: unknown) { ? matcherHint('.not.toBeArray', 'received', '') + '\n\n' + 'Expected value to not be an array received:\n' + - ` ${printReceived(expected)}` + ` ${printReceived(actual)}` : matcherHint('.toBeArray', 'received', '') + '\n\n' + 'Expected value to be an array received:\n' + - ` ${printReceived(expected)}`, + ` ${printReceived(actual)}`, }; } diff --git a/src/matchers/toBeArrayOfSize.ts b/src/matchers/toBeArrayOfSize.ts index df972f5a..1b6be4aa 100644 --- a/src/matchers/toBeArrayOfSize.ts +++ b/src/matchers/toBeArrayOfSize.ts @@ -1,5 +1,9 @@ import { determinePropertyMessage } from 'src/utils'; +/** + * Use `.toBeArrayOfSize` when checking if a value is an `Array` of size x. + * @param {Number} expected + */ export function toBeArrayOfSize(actual: unknown, expected: number) { // @ts-expect-error OK to have implicit any for this.utils const { printExpected, printReceived, matcherHint } = this.utils; diff --git a/src/matchers/toBeBefore.ts b/src/matchers/toBeBefore.ts index 986884e3..f2cdd3d6 100644 --- a/src/matchers/toBeBefore.ts +++ b/src/matchers/toBeBefore.ts @@ -1,3 +1,6 @@ +/** + * Use `.toBeBefore` when checking if a date occurs before `date`* @param {Date} expected + */ export function toBeBefore(actual: unknown, expected: Date) { // @ts-expect-error OK to have implicit any for this.utils const { matcherHint, printReceived } = this.utils; diff --git a/src/matchers/toBeBeforeOrEqualTo.ts b/src/matchers/toBeBeforeOrEqualTo.ts index 04314be5..15623ec6 100644 --- a/src/matchers/toBeBeforeOrEqualTo.ts +++ b/src/matchers/toBeBeforeOrEqualTo.ts @@ -1,3 +1,7 @@ +/** + * Use `.toBeBeforeOrEqualTo` when checking if a date equals to or occurs before `date`. + * @param {Date} date + */ export function toBeBeforeOrEqualTo(actual: unknown, expected: Date) { // @ts-expect-error OK to have implicit any for this.utils const { matcherHint, printReceived } = this.utils; diff --git a/src/matchers/toBeBetween.ts b/src/matchers/toBeBetween.ts index b98218de..abf7c275 100644 --- a/src/matchers/toBeBetween.ts +++ b/src/matchers/toBeBetween.ts @@ -1,3 +1,8 @@ +/** + * Use `.toBeBetween` when checking if a date occurs between `startDate` and `endDate`. + * @param {Date} startDate + * @param {Date} endDate + */ export function toBeBetween(actual: unknown, startDate: Date, endDate: Date) { // @ts-expect-error OK to have implicit any for this.utils const { matcherHint, printReceived } = this.utils; diff --git a/src/matchers/toBeBoolean.ts b/src/matchers/toBeBoolean.ts index c1f013a2..ebad6d86 100644 --- a/src/matchers/toBeBoolean.ts +++ b/src/matchers/toBeBoolean.ts @@ -1,3 +1,6 @@ +/** + * Use `.toBeBoolean` when checking if a value is a `Boolean`. + */ export function toBeBoolean(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { matcherHint, printReceived } = this.utils; diff --git a/src/matchers/toBeDate.ts b/src/matchers/toBeDate.ts index a8d7d6f4..90d29363 100644 --- a/src/matchers/toBeDate.ts +++ b/src/matchers/toBeDate.ts @@ -1,3 +1,6 @@ +/** + * Use `.toBeDate` when checking if a value is a `Date`. + */ export function toBeDate(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { matcherHint, printReceived } = this.utils; diff --git a/src/matchers/toBeDateString.ts b/src/matchers/toBeDateString.ts index ee65da21..16cf3085 100644 --- a/src/matchers/toBeDateString.ts +++ b/src/matchers/toBeDateString.ts @@ -1,3 +1,6 @@ +/** + * Use `.toBeDateString` when checking if a value is a valid date string. + */ export function toBeDateString(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { matcherHint, printReceived } = this.utils; diff --git a/src/matchers/toBeEmpty.ts b/src/matchers/toBeEmpty.ts index f9b520aa..a142525e 100644 --- a/src/matchers/toBeEmpty.ts +++ b/src/matchers/toBeEmpty.ts @@ -1,3 +1,6 @@ +/** + * Use .toBeEmpty when checking if a String '', Array [], Object {} is empty. + */ export function toBeEmpty(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, matcherHint } = this.utils; diff --git a/src/matchers/toBeEmptyObject.ts b/src/matchers/toBeEmptyObject.ts index cfadc338..227d887e 100644 --- a/src/matchers/toBeEmptyObject.ts +++ b/src/matchers/toBeEmptyObject.ts @@ -1,3 +1,6 @@ +/** + * Use `.toBeEmptyObject` when checking if a value is an empty `Object`. + */ export function toBeEmptyObject(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, matcherHint } = this.utils; diff --git a/src/matchers/toBeEven.ts b/src/matchers/toBeEven.ts index 785bc161..f8bbfc40 100644 --- a/src/matchers/toBeEven.ts +++ b/src/matchers/toBeEven.ts @@ -1,3 +1,6 @@ +/** + * Use `.toBeEven` when checking if a value is an even `Number`. + */ export function toBeEven(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, matcherHint } = this.utils; diff --git a/src/matchers/toBeExtensible.ts b/src/matchers/toBeExtensible.ts index 1d231467..97ba9cda 100644 --- a/src/matchers/toBeExtensible.ts +++ b/src/matchers/toBeExtensible.ts @@ -1,3 +1,6 @@ +/** + * Use `.toBeExtensible` when checking if an object is extensible. + */ export function toBeExtensible(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { matcherHint, printExpected, printReceived } = this.utils; diff --git a/src/matchers/toBeFalse.ts b/src/matchers/toBeFalse.ts index 073168ae..6b2ec613 100644 --- a/src/matchers/toBeFalse.ts +++ b/src/matchers/toBeFalse.ts @@ -1,3 +1,6 @@ +/** + * Use `.toBeFalse` when checking a value is equal (===) to `false`. + */ export function toBeFalse(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, matcherHint, printExpected } = this.utils; diff --git a/src/matchers/toBeFinite.ts b/src/matchers/toBeFinite.ts index f87bddab..7167ba6e 100644 --- a/src/matchers/toBeFinite.ts +++ b/src/matchers/toBeFinite.ts @@ -1,3 +1,6 @@ +/** + * Use `.toBeFinite` when checking if a value is a `Number`, not `NaN` or `Infinity`. + */ export function toBeFinite(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, matcherHint } = this.utils; diff --git a/src/matchers/toBeFrozen.ts b/src/matchers/toBeFrozen.ts index 0ebc0a3b..fb075941 100644 --- a/src/matchers/toBeFrozen.ts +++ b/src/matchers/toBeFrozen.ts @@ -1,3 +1,6 @@ +/** + * Use `.toBeFrozen` when checking if an object is frozen. + */ export function toBeFrozen(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { matcherHint } = this.utils; diff --git a/src/matchers/toBeFunction.ts b/src/matchers/toBeFunction.ts index fe37eae6..7196a88f 100644 --- a/src/matchers/toBeFunction.ts +++ b/src/matchers/toBeFunction.ts @@ -1,3 +1,6 @@ +/** + * Use `.toBeFunction` when checking if a value is a `Function`. + */ export function toBeFunction(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, matcherHint } = this.utils; diff --git a/src/matchers/toBeHexadecimal.ts b/src/matchers/toBeHexadecimal.ts index 4176195f..bca63e0c 100644 --- a/src/matchers/toBeHexadecimal.ts +++ b/src/matchers/toBeHexadecimal.ts @@ -1,3 +1,6 @@ +/** + * Use `.toBeHexadecimal` when checking if a value is a valid HTML hex color. + */ export function toBeHexadecimal(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, matcherHint } = this.utils; diff --git a/src/matchers/toBeInRange.ts b/src/matchers/toBeInRange.ts index 8be5c205..51ecda84 100644 --- a/src/matchers/toBeInRange.ts +++ b/src/matchers/toBeInRange.ts @@ -1,3 +1,9 @@ +/** + * Use `.toBeInRange` when checking if an array has elements in range min (inclusive) and max (exclusive). + * + * @param min + * @param max + */ export function toBeInRange(actual: unknown[], min: number, max: number) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toBeInteger.ts b/src/matchers/toBeInteger.ts index 365c1966..6c2581f1 100644 --- a/src/matchers/toBeInteger.ts +++ b/src/matchers/toBeInteger.ts @@ -1,3 +1,6 @@ +/** + * Use `.toBeInteger` when checking if a value is an integer. + */ export function toBeInteger(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, matcherHint } = this.utils; diff --git a/src/matchers/toBeNaN.ts b/src/matchers/toBeNaN.ts index 5dea1196..bce95b19 100644 --- a/src/matchers/toBeNaN.ts +++ b/src/matchers/toBeNaN.ts @@ -1,3 +1,6 @@ +/** + * Use `.toBeNaN` when checking a value is `NaN`. + */ export function toBeNaN(actual: any) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, matcherHint } = this.utils; diff --git a/src/matchers/toBeNegative.ts b/src/matchers/toBeNegative.ts index c77ffb99..57766b8e 100644 --- a/src/matchers/toBeNegative.ts +++ b/src/matchers/toBeNegative.ts @@ -1,3 +1,6 @@ +/** + * Use `.toBeNegative` when checking if a value is a negative `Number`. + */ export function toBeNegative(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, matcherHint } = this.utils; diff --git a/src/matchers/toBeNil.ts b/src/matchers/toBeNil.ts index 327dfe38..0b763ec2 100644 --- a/src/matchers/toBeNil.ts +++ b/src/matchers/toBeNil.ts @@ -1,3 +1,6 @@ +/** + * Use `.toBeNil` when checking a value is `null` or `undefined`. + */ export function toBeNil(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, matcherHint } = this.utils; diff --git a/src/matchers/toBeNumber.ts b/src/matchers/toBeNumber.ts index ae9c49c1..acd29ce5 100644 --- a/src/matchers/toBeNumber.ts +++ b/src/matchers/toBeNumber.ts @@ -1,3 +1,6 @@ +/** + * Use `.toBeNumber` when checking if a value is a `Number`. + */ export function toBeNumber(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, matcherHint } = this.utils; diff --git a/src/matchers/toBeObject.ts b/src/matchers/toBeObject.ts index 0e09b3f8..97687920 100644 --- a/src/matchers/toBeObject.ts +++ b/src/matchers/toBeObject.ts @@ -1,3 +1,6 @@ +/** + * Use `.toBeObject` when checking if a value is an `Object`. + */ export function toBeObject(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, matcherHint } = this.utils; diff --git a/src/matchers/toBeOdd.ts b/src/matchers/toBeOdd.ts index d6bf0ee7..5ea580a9 100644 --- a/src/matchers/toBeOdd.ts +++ b/src/matchers/toBeOdd.ts @@ -1,3 +1,6 @@ +/** + * Use `.toBeOdd` when checking if a value is an odd `Number`. + */ export function toBeOdd(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, matcherHint } = this.utils; diff --git a/src/matchers/toBeOneOf.ts b/src/matchers/toBeOneOf.ts index 83ee9c5d..7f14ab0e 100644 --- a/src/matchers/toBeOneOf.ts +++ b/src/matchers/toBeOneOf.ts @@ -1,5 +1,9 @@ import { contains } from 'src/utils'; +/** + * Use .toBeOneOf when checking if a value is a member of a given Array. + * @param {Array.<*>} expected + */ export function toBeOneOf(actual: unknown, expected: readonly E[]) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toBePositive.ts b/src/matchers/toBePositive.ts index 3094d6cc..bda62c57 100644 --- a/src/matchers/toBePositive.ts +++ b/src/matchers/toBePositive.ts @@ -1,3 +1,6 @@ +/** + * Use `.toBePositive` when checking if a value is a positive `Number`. + */ export function toBePositive(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, matcherHint } = this.utils; diff --git a/src/matchers/toBeSealed.ts b/src/matchers/toBeSealed.ts index 3eb4083d..2c1118b9 100644 --- a/src/matchers/toBeSealed.ts +++ b/src/matchers/toBeSealed.ts @@ -1,3 +1,6 @@ +/** + * Use `.toBeSealed` when checking if an object is sealed. + */ export function toBeSealed(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { matcherHint } = this.utils; diff --git a/src/matchers/toBeString.ts b/src/matchers/toBeString.ts index 6684ad5f..679b2139 100644 --- a/src/matchers/toBeString.ts +++ b/src/matchers/toBeString.ts @@ -1,8 +1,11 @@ -export function toBeString(expected: unknown) { +/** + * Use `.toBeString` when checking if a value is a `String`. + */ +export function toBeString(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; - const pass = typeof expected === 'string' || expected instanceof String; + const pass = typeof actual === 'string' || actual instanceof String; return { pass, @@ -11,12 +14,12 @@ export function toBeString(expected: unknown) { ? matcherHint('.not.toBeString', 'received', '') + '\n\n' + 'Expected value to not be of type string received:\n' + - ` ${printReceived(expected)}` + ` ${printReceived(actual)}` : matcherHint('.toBeString', 'received', '') + '\n\n' + 'Expected value to be of type string:\n' + ` ${printExpected('type of string')}\n` + 'Received:\n' + - ` ${printReceived(typeof expected)}`, + ` ${printReceived(typeof actual)}`, }; } diff --git a/src/matchers/toBeSymbol.ts b/src/matchers/toBeSymbol.ts index dd994200..887cca6c 100644 --- a/src/matchers/toBeSymbol.ts +++ b/src/matchers/toBeSymbol.ts @@ -1,3 +1,6 @@ +/** + * Use `.toBeSymbol` when checking if a value is a `Symbol`. + */ export function toBeSymbol(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, matcherHint } = this.utils; diff --git a/src/matchers/toBeTrue.ts b/src/matchers/toBeTrue.ts index 2c57e044..9b2e75fe 100644 --- a/src/matchers/toBeTrue.ts +++ b/src/matchers/toBeTrue.ts @@ -1,3 +1,6 @@ +/** + * Use `.toBeTrue` when checking a value is equal (===) to `true`. + */ export function toBeTrue(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toBeValidDate.ts b/src/matchers/toBeValidDate.ts index 2e89485e..d0934ff2 100644 --- a/src/matchers/toBeValidDate.ts +++ b/src/matchers/toBeValidDate.ts @@ -1,3 +1,6 @@ +/** + * Use `.toBeValidDate` when checking if a value is a `valid Date`. + */ export function toBeValidDate(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, matcherHint } = this.utils; diff --git a/src/matchers/toBeWithin.ts b/src/matchers/toBeWithin.ts index 86d017a7..cc252397 100644 --- a/src/matchers/toBeWithin.ts +++ b/src/matchers/toBeWithin.ts @@ -1,3 +1,9 @@ +/** + * Use `.toBeWithin` when checking if a number is in between the given bounds of: start (inclusive) and end (exclusive). + * + * @param {Number} start + * @param {Number} end + */ export function toBeWithin(actual: unknown, start: number, end: number) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toChange.ts b/src/matchers/toChange.ts index 414b2792..390ee756 100644 --- a/src/matchers/toChange.ts +++ b/src/matchers/toChange.ts @@ -1,5 +1,6 @@ /** * Use `.toChange` when checking if a value has changed. + * @param {Function} checker */ export function toChange(mutator: () => unknown | void, checker: () => number) { // @ts-expect-error OK to have implicit any for this.utils diff --git a/src/matchers/toChangeBy.ts b/src/matchers/toChangeBy.ts index 1ba7de0d..abbe1fd7 100644 --- a/src/matchers/toChangeBy.ts +++ b/src/matchers/toChangeBy.ts @@ -1,5 +1,7 @@ /** * Use `.toChangeBy` when checking if a value changed by an amount. + * @param {Function} checker + * @param {Number} by */ export function toChangeBy(mutator: () => unknown | void, checker: () => number, by: number = 1) { // @ts-expect-error OK to have implicit any for this.utils diff --git a/src/matchers/toChangeTo.ts b/src/matchers/toChangeTo.ts index 32f3361f..9443011c 100644 --- a/src/matchers/toChangeTo.ts +++ b/src/matchers/toChangeTo.ts @@ -1,7 +1,10 @@ /** * Use `.toChangeTo` when checking if a value changed to a specific value. + * @param {Function} mutator - Function that mutates the value. + * @param {Function} checker - Function that checks the value. + * @param {number} to - The value to check against. */ -export function toChangeTo(mutator: () => unknown | void, checker: () => number, to: number) { +export function toChangeTo(mutator: () => unknown | void, checker: () => E, to: E) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived: print, matcherHint: hint } = this.utils; diff --git a/src/matchers/toContainAllEntries.ts b/src/matchers/toContainAllEntries.ts index c88361bc..f0e1f38e 100644 --- a/src/matchers/toContainAllEntries.ts +++ b/src/matchers/toContainAllEntries.ts @@ -1,5 +1,10 @@ import { containsEntry } from 'src/utils'; +/** + * Use `.toContainAllEntries` when checking if an object only contains all of the provided entries. + * + * @param {Array.>} entries + */ export function toContainAllEntries( actual: unknown, expected: readonly (readonly [keyof E, E[keyof E]])[], diff --git a/src/matchers/toContainAllKeys.ts b/src/matchers/toContainAllKeys.ts index f6535c5d..457317d6 100644 --- a/src/matchers/toContainAllKeys.ts +++ b/src/matchers/toContainAllKeys.ts @@ -1,5 +1,9 @@ import { contains } from 'src/utils'; +/** + * Use `.toContainAllKeys` when checking if an object only contains all of the provided keys. + * @param {Array.} keys + */ export function toContainAllKeys(actual: unknown, expected: readonly (keyof E | string)[]) { // @ts-expect-error OK to have implicit any for this.utils const { printExpected, printReceived, matcherHint } = this.utils; diff --git a/src/matchers/toContainAllValues.ts b/src/matchers/toContainAllValues.ts index c22c18b1..33052674 100644 --- a/src/matchers/toContainAllValues.ts +++ b/src/matchers/toContainAllValues.ts @@ -1,5 +1,10 @@ import { contains } from 'src/utils'; +/** + * Use `.toContainAllValues` when checking if an object only contains all of the provided values. + * + * @param {Array.<*>} values + */ export function toContainAllValues(actual: unknown, expected: readonly E[]) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toContainAnyEntries.ts b/src/matchers/toContainAnyEntries.ts index 94c0fb89..87810d70 100644 --- a/src/matchers/toContainAnyEntries.ts +++ b/src/matchers/toContainAnyEntries.ts @@ -1,5 +1,10 @@ import { contains } from 'src/utils'; +/** + * Use `.toContainAnyEntries` when checking if an object contains at least one of the provided entries. + * + * @param {Array.>} entries + */ export function toContainAnyEntries( actual: unknown, expected: readonly (readonly [keyof E, E[keyof E]])[], diff --git a/src/matchers/toContainAnyKeys.ts b/src/matchers/toContainAnyKeys.ts index ce3123db..4f15e111 100644 --- a/src/matchers/toContainAnyKeys.ts +++ b/src/matchers/toContainAnyKeys.ts @@ -1,3 +1,8 @@ +/** + * Use `.toContainAnyKeys` when checking if an object contains at least one of the provided keys. + * + * @param {Array.} keys + */ export function toContainAnyKeys(actual: unknown, expected: readonly (keyof E | string)[]) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toContainAnyValues.ts b/src/matchers/toContainAnyValues.ts index 8ca8acea..6b39118f 100644 --- a/src/matchers/toContainAnyValues.ts +++ b/src/matchers/toContainAnyValues.ts @@ -1,5 +1,10 @@ import { contains } from 'src/utils'; +/** + * Use `.toContainAnyValues` when checking if an object contains at least one of the provided values. + * + * @param {Array.<*>} values + */ export function toContainAnyValues(actual: unknown, expected: readonly E[]) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toContainEntries.ts b/src/matchers/toContainEntries.ts index 5311a727..a5d7035d 100644 --- a/src/matchers/toContainEntries.ts +++ b/src/matchers/toContainEntries.ts @@ -1,5 +1,10 @@ import { containsEntry } from 'src/utils'; +/** + * Use `.toContainEntries` when checking if an object contains all of the provided entries. + * + * @param {Array.>} entries + */ export function toContainEntries(actual: unknown, expected: readonly (readonly [keyof E, E[keyof E]])[]) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toContainEntry.ts b/src/matchers/toContainEntry.ts index a320ea81..7613b5bc 100644 --- a/src/matchers/toContainEntry.ts +++ b/src/matchers/toContainEntry.ts @@ -1,5 +1,10 @@ import { containsEntry } from 'src/utils'; +/** + * Use `.toContainEntry` when checking if an object contains the provided entry. + * + * @param {Array.<[keyof E, E[keyof E]>} entry + */ export function toContainEntry(actual: unknown, expected: readonly [keyof E, E[keyof E]]) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toContainKey.ts b/src/matchers/toContainKey.ts index 61ee7feb..3f73c4a1 100644 --- a/src/matchers/toContainKey.ts +++ b/src/matchers/toContainKey.ts @@ -1,3 +1,8 @@ +/** + * Use `.toContainKey` when checking if an object contains the provided key. + * + * @param {String} key + */ export function toContainKey(actual: unknown, expected: keyof E | string) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toContainKeys.ts b/src/matchers/toContainKeys.ts index 6dfcdcd8..8c752a7e 100644 --- a/src/matchers/toContainKeys.ts +++ b/src/matchers/toContainKeys.ts @@ -1,3 +1,8 @@ +/** + * Use `.toContainKeys` when checking if an object has all of the provided keys. + * + * @param {Array.} keys + */ export function toContainKeys(actual: unknown, expected: readonly (keyof E | string)[]) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toContainValue.ts b/src/matchers/toContainValue.ts index a570899a..ce4c023c 100644 --- a/src/matchers/toContainValue.ts +++ b/src/matchers/toContainValue.ts @@ -1,5 +1,10 @@ import { contains } from 'src/utils'; +/** + * Use `.toContainValue` when checking if an object contains the provided value. + * + * @param {*} value + */ export function toContainValue(actual: unknown, expected: E) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toContainValues.ts b/src/matchers/toContainValues.ts index 077c58d8..ca1ff9e5 100644 --- a/src/matchers/toContainValues.ts +++ b/src/matchers/toContainValues.ts @@ -1,5 +1,10 @@ import { contains } from 'src/utils'; +/** + * Use `.toContainValues` when checking if an object contains all of the provided values. + * + * @param {Array.<*>} values + */ export function toContainValues(actual: unknown, expected: readonly E[]) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toEndWith.ts b/src/matchers/toEndWith.ts index ac521f2d..1a83ea84 100644 --- a/src/matchers/toEndWith.ts +++ b/src/matchers/toEndWith.ts @@ -1,3 +1,8 @@ +/** + * Use `.toEndWith` when checking if a `String` ends with a given `String` suffix. + * + * @param {String} suffix + */ export function toEndWith(actual: unknown, expected: string) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toEqualCaseInsensitive.ts b/src/matchers/toEqualCaseInsensitive.ts index cc1ce5b8..03049341 100644 --- a/src/matchers/toEqualCaseInsensitive.ts +++ b/src/matchers/toEqualCaseInsensitive.ts @@ -1,3 +1,8 @@ +/** + * Use `.toEqualCaseInsensitive` when checking if a string is equal (===) to another ignoring the casing of both strings. + * + * @param {String} string + */ export function toEqualCaseInsensitive(actual: unknown, expected: string) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toEqualIgnoringWhitespace.ts b/src/matchers/toEqualIgnoringWhitespace.ts index fb289ae7..1bdb278c 100644 --- a/src/matchers/toEqualIgnoringWhitespace.ts +++ b/src/matchers/toEqualIgnoringWhitespace.ts @@ -16,6 +16,11 @@ const getDiff = (received: string, expected: string) => { return diff; }; +/** + * Use `.toEqualIgnoringWhitespace` when checking if a `String` is equal (===) to given `String` ignoring white-space. + * + * @param {String} string + */ export function toEqualIgnoringWhitespace(actual: unknown, expected: string) { // @ts-expect-error OK to have implicit any for this.utils const { matcherHint, EXPECTED_COLOR } = this.utils; diff --git a/src/matchers/toHaveBeenCalledAfter.ts b/src/matchers/toHaveBeenCalledAfter.ts index 8ea5bfa4..18680bc3 100644 --- a/src/matchers/toHaveBeenCalledAfter.ts +++ b/src/matchers/toHaveBeenCalledAfter.ts @@ -1,5 +1,13 @@ import { isJestMockOrSpy } from 'src/utils'; +/** + * Use `.toHaveBeenCalledAfter` when checking if a `Mock` was called after another `Mock`. + * + * Note: Required Jest version >=23 + * + * @param {Mock} mock + * @param {boolean} [failIfNoFirstInvocation=true] + */ export function toHaveBeenCalledAfter( actual: unknown, expected: jest.MockInstance, diff --git a/src/matchers/toHaveBeenCalledBefore.ts b/src/matchers/toHaveBeenCalledBefore.ts index aa6c6571..5ea99464 100644 --- a/src/matchers/toHaveBeenCalledBefore.ts +++ b/src/matchers/toHaveBeenCalledBefore.ts @@ -1,5 +1,13 @@ import { isJestMockOrSpy } from 'src/utils'; +/** + * Use `.toHaveBeenCalledBefore` when checking if a `Mock` was called before another `Mock`. + * + * Note: Required Jest version >=23 + * + * @param {Mock} mock + * @param {boolean} [failIfNoSecondInvocation=true] + */ export function toHaveBeenCalledBefore( actual: unknown, expected: jest.MockInstance, diff --git a/src/matchers/toHaveBeenCalledExactlyOnceWith.ts b/src/matchers/toHaveBeenCalledExactlyOnceWith.ts index 2f20472e..6e4b274b 100644 --- a/src/matchers/toHaveBeenCalledExactlyOnceWith.ts +++ b/src/matchers/toHaveBeenCalledExactlyOnceWith.ts @@ -1,5 +1,8 @@ import { isJestMockOrSpy } from 'src/utils'; +/** + * Use `.toHaveBeenCalledExactlyOnceWith` to check if a `Mock` was called exactly one time with the expected value. + */ export function toHaveBeenCalledExactlyOnceWith(received: unknown, ...expected: unknown[]) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, printWithType, matcherHint } = this.utils; diff --git a/src/matchers/toHaveBeenCalledOnce.ts b/src/matchers/toHaveBeenCalledOnce.ts index a3cb6970..94695850 100644 --- a/src/matchers/toHaveBeenCalledOnce.ts +++ b/src/matchers/toHaveBeenCalledOnce.ts @@ -1,5 +1,8 @@ import { isJestMockOrSpy } from 'src/utils'; +/** + * Use `.toHaveBeenCalledOnce` to check if a `Mock` was called exactly one time. + */ export function toHaveBeenCalledOnce(actual: unknown) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printWithType, matcherHint } = this.utils; diff --git a/src/matchers/toInclude.ts b/src/matchers/toInclude.ts index a1c567cf..a47113c7 100644 --- a/src/matchers/toInclude.ts +++ b/src/matchers/toInclude.ts @@ -1,3 +1,8 @@ +/** + * Use `.toInclude` when checking if a `String` includes the given `String` substring. + * + * @param {String} substring + */ export function toInclude(actual: unknown, expected: string) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toIncludeAllMembers.ts b/src/matchers/toIncludeAllMembers.ts index cdd363bd..a302faf5 100644 --- a/src/matchers/toIncludeAllMembers.ts +++ b/src/matchers/toIncludeAllMembers.ts @@ -1,5 +1,9 @@ import { contains } from 'src/utils'; +/** + * Use `.toIncludeAllMembers` when checking if an `Array` contains all of the same members of a given set. + * @param {Array.<*>} members + */ export function toIncludeAllMembers(actual: unknown[], expected: readonly E[] | E) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toIncludeAllPartialMembers.ts b/src/matchers/toIncludeAllPartialMembers.ts index 6a94c555..4612a363 100644 --- a/src/matchers/toIncludeAllPartialMembers.ts +++ b/src/matchers/toIncludeAllPartialMembers.ts @@ -1,5 +1,9 @@ import { containsEntry } from 'src/utils'; +/** + * Use `.toIncludeAllPartialMembers` when checking if an `Array` contains all the same partial members of a given set. + * @param {Array.<*>} members + */ export function toIncludeAllPartialMembers(actual: unknown, expected: readonly E[] | E) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toIncludeAnyMembers.ts b/src/matchers/toIncludeAnyMembers.ts index 9c0beae8..c9f7cdbe 100644 --- a/src/matchers/toIncludeAnyMembers.ts +++ b/src/matchers/toIncludeAnyMembers.ts @@ -1,5 +1,9 @@ import { contains } from 'src/utils'; +/** + * Use `.toIncludeAnyMembers` when checking if an `Array` contains any of the members of a given set. + * @param {Array.<*>} members + */ export function toIncludeAnyMembers(actual: unknown, expected: readonly E[] | E) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toIncludeMultiple.ts b/src/matchers/toIncludeMultiple.ts index 8623567d..8e557c91 100644 --- a/src/matchers/toIncludeMultiple.ts +++ b/src/matchers/toIncludeMultiple.ts @@ -1,3 +1,8 @@ +/** + * Use `.toIncludeMultiple` when checking if a `String` includes all of the given substrings. + * + * @param {Array.} substring + */ export function toIncludeMultiple(actual: unknown, expected: readonly string[]) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toIncludeRepeated.ts b/src/matchers/toIncludeRepeated.ts index 80fbbd64..6e1187dc 100644 --- a/src/matchers/toIncludeRepeated.ts +++ b/src/matchers/toIncludeRepeated.ts @@ -1,3 +1,9 @@ +/** + * Use `.toIncludeRepeated` when checking if a `String` includes the given `String` substring the correct number of times. + * + * @param {String} substring + * @param {Number} times + */ export function toIncludeRepeated(actual: unknown, expected: string, occurrences: number) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toIncludeSameMembers.ts b/src/matchers/toIncludeSameMembers.ts index a77604dc..8c1cf675 100644 --- a/src/matchers/toIncludeSameMembers.ts +++ b/src/matchers/toIncludeSameMembers.ts @@ -1,3 +1,7 @@ +/** + * Use `.toIncludeSameMembers` when checking if two arrays contain equal values, in any order. + * @param {Array.<*>} members + */ export function toIncludeSameMembers(actual: unknown, expected: readonly E[]) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toIncludeSamePartialMembers.ts b/src/matchers/toIncludeSamePartialMembers.ts index ca787dc6..dcef14e8 100644 --- a/src/matchers/toIncludeSamePartialMembers.ts +++ b/src/matchers/toIncludeSamePartialMembers.ts @@ -1,5 +1,9 @@ import { containsEntry } from '../utils'; +/** + * Use `.toIncludeSamePartialMembers` when checking if an `Array` contains exactly the same partial members as a given set, in any order + * @param {Array.<*>} members + */ export function toIncludeSamePartialMembers(actual: unknown, expected: E) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toPartiallyContain.ts b/src/matchers/toPartiallyContain.ts index b133fab5..38dabc1b 100644 --- a/src/matchers/toPartiallyContain.ts +++ b/src/matchers/toPartiallyContain.ts @@ -1,5 +1,9 @@ import { containsEntry } from 'src/utils'; +/** + * Use `.toPartiallyContain` when checking if any array value matches the partial member. + * @param {*} member + */ export function toPartiallyContain(actual: unknown, expected: E) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toReject.ts b/src/matchers/toReject.ts index 4b8225e8..c740f4ec 100644 --- a/src/matchers/toReject.ts +++ b/src/matchers/toReject.ts @@ -1,3 +1,6 @@ +/** + * Use `.toReject` when checking if a promise rejects. + */ export async function toReject(actual: Promise) { // @ts-expect-error OK to have implicit any for this.utils const { matcherHint } = this.utils; diff --git a/src/matchers/toResolve.ts b/src/matchers/toResolve.ts index b1b79345..7b4bac05 100644 --- a/src/matchers/toResolve.ts +++ b/src/matchers/toResolve.ts @@ -1,3 +1,6 @@ +/** + * Use `.toResolve` when checking if a promise resolves. + */ export async function toResolve(actual: Promise) { // @ts-expect-error OK to have implicit any for this.utils const { matcherHint } = this.utils; diff --git a/src/matchers/toSatisfy.ts b/src/matchers/toSatisfy.ts index f414024d..a826c355 100644 --- a/src/matchers/toSatisfy.ts +++ b/src/matchers/toSatisfy.ts @@ -1,3 +1,7 @@ +/** + * Use `.toSatisfy` when you want to use a custom matcher by supplying a predicate function that returns a `Boolean`. + * @param {Function} expected + */ export function toSatisfy(actual: E, expected: (x: E) => boolean) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toSatisfyAll.ts b/src/matchers/toSatisfyAll.ts index 1b87a67f..f8de8477 100644 --- a/src/matchers/toSatisfyAll.ts +++ b/src/matchers/toSatisfyAll.ts @@ -1,3 +1,7 @@ +/** + * Use `.toSatisfyAll` when you want to use a custom matcher by supplying a predicate function that returns a `Boolean` for all values in an array. + * @param {Function} predicate + */ export function toSatisfyAll(actual: E[], expected: (x: E) => boolean) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toSatisfyAny.ts b/src/matchers/toSatisfyAny.ts index 0ce58800..0d121587 100644 --- a/src/matchers/toSatisfyAny.ts +++ b/src/matchers/toSatisfyAny.ts @@ -1,4 +1,8 @@ -export function toSatisfyAny(actual: unknown, expected: (x: unknown) => boolean) { +/** + * Use `.toSatisfyAny` when you want to use a custom matcher by supplying a predicate function that returns `true` for any matching value in an array. + * @param {Function} predicate + */ +export function toSatisfyAny(actual: unknown, expected: (x: any) => boolean) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toStartWith.ts b/src/matchers/toStartWith.ts index ca52bb41..8944437c 100644 --- a/src/matchers/toStartWith.ts +++ b/src/matchers/toStartWith.ts @@ -1,3 +1,8 @@ +/** + * Use `.toStartWith` when checking if a `String` starts with a given `String` prefix. + * + * @param {String} prefix + */ export function toStartWith(actual: unknown, expected: string) { // @ts-expect-error OK to have implicit any for this.utils const { printReceived, printExpected, matcherHint } = this.utils; diff --git a/src/matchers/toThrowWithMessage.ts b/src/matchers/toThrowWithMessage.ts index 24e205e2..63b82438 100644 --- a/src/matchers/toThrowWithMessage.ts +++ b/src/matchers/toThrowWithMessage.ts @@ -41,6 +41,12 @@ const getExpectedError = (type: any, message: any) => { return expectedError; }; +/** + * Use `.toThrowWithMessage` when checking if a callback function throws an error of a given type with a given error message. + * + * @param {Function} type + * @param {String | RegExp} message + */ export function toThrowWithMessage( callbackOrPromiseReturn: () => void, type: diff --git a/test/matchers/toIncludeSamePartialMembers.test.ts b/test/matchers/toIncludeSamePartialMembers.test.ts index c0ffa37d..5d03883e 100644 --- a/test/matchers/toIncludeSamePartialMembers.test.ts +++ b/test/matchers/toIncludeSamePartialMembers.test.ts @@ -38,7 +38,6 @@ describe('.toIncludeSamePartialMembers', () => { test('fails when expected object is not an array', () => { expect(() => - // @ts-expect-error this is intentional for the test expect([{ hello: 'world' }, { foo: 'bar', baz: 'qux' }]).toIncludeSamePartialMembers(1), ).toThrowErrorMatchingSnapshot(); }); diff --git a/tsconfig.json b/tsconfig.json index 113b43e9..c61ed26e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,5 @@ { "compilerOptions": { - "incremental": true, "tsBuildInfoFile": "./.tsbuildinfo", "target": "es2022", "module": "CommonJS", @@ -20,11 +19,10 @@ "src/*": [ "src/*" ] - }, + } }, "include": [ - "src/**/*", - "types/*", + "src/**/*" ], "exclude": [ "node_modules", diff --git a/tsconfig.test.json b/tsconfig.test.json index 51f525c7..34e8bc4c 100644 --- a/tsconfig.test.json +++ b/tsconfig.test.json @@ -1,6 +1,5 @@ { "compilerOptions": { - "incremental": true, "tsBuildInfoFile": "./.tsbuildinfo", "target": "es2022", "module": "CommonJS", @@ -28,7 +27,7 @@ "include": [ "src/**/*", "test/**/*", - "types/*", + "types/*" ], "exclude": [ "node_modules", diff --git a/types/index.d.ts b/types/index.d.ts deleted file mode 100644 index dc6a2752..00000000 --- a/types/index.d.ts +++ /dev/null @@ -1,942 +0,0 @@ -interface CustomMatchers extends Record { - /** - * Note: Currently unimplemented - * Passing assertion - * - * @param {String} message - */ - pass(message: string): R; - - /** - * Note: Currently unimplemented - * Failing assertion - * - * @param {String} message - */ - fail(message: string): R; - - /** - * Use .toBeEmpty when checking if a String '', Array [] or Object {} is empty. - */ - toBeEmpty(): R; - - /** - * Use .toBeOneOf when checking if a value is a member of a given Array. - * @param {Array.<*>} members - */ - toBeOneOf(members: readonly E[]): R; - - /** - * Use `.toBeNil` when checking a value is `null` or `undefined`. - */ - toBeNil(): R; - - /** - * Use `.toSatisfy` when you want to use a custom matcher by supplying a predicate function that returns a `Boolean`. - * @param {Function} predicate - */ - toSatisfy(predicate: (x: E) => boolean): R; - - /** - * Use `.toBeArray` when checking if a value is an `Array`. - */ - toBeArray(): R; - - /** - * Use `.toBeArrayOfSize` when checking if a value is an `Array` of size x. - * @param {Number} x - */ - toBeArrayOfSize(x: number): R; - - /** - * Use `.toBeAfter` when checking if a date occurs after `date`. - * @param {Date} date - */ - toBeAfter(date: Date): R; - - /** - * Use `.toBeBefore` when checking if a date occurs before `date`. - * @param {Date} date - */ - toBeBefore(date: Date): R; - - /** - * Use `.toIncludeAllMembers` when checking if an `Array` contains all of the same members of a given set. - * @param {Array.<*>} members - */ - toIncludeAllMembers(members: readonly E[] | E): R; - - /** - * Use `.toIncludeAllPartialMembers` when checking if an `Array` contains all the same partial members of a given set. - * @param {Array.<*>} members - */ - toIncludeAllPartialMembers(members: readonly E[] | E): R; - - /** - * Use `.toIncludeSamePartialMembers` when checking if an `Array` contains exactly the same partial members as a given set, in any order - * @param {Array.<*>} members - */ - toIncludeSamePartialMembers(members: readonly E[]): R; - - /** - * Use `.toIncludeAnyMembers` when checking if an `Array` contains any of the members of a given set. - * @param {Array.<*>} members - */ - toIncludeAnyMembers(members: readonly E[] | E): R; - - /** - * Use `.toIncludeSameMembers` when checking if two arrays contain equal values, in any order. - * @param {Array.<*>} members - */ - toIncludeSameMembers(members: readonly E[]): R; - - /** - * Use `.toPartiallyContain` when checking if any array value matches the partial member. - * @param {*} member - */ - toPartiallyContain(member: E): R; - - /** - * Use `.toSatisfyAll` when you want to use a custom matcher by supplying a predicate function that returns a `Boolean` for all values in an array. - * @param {Function} predicate - */ - toSatisfyAll(predicate: (x: E) => boolean): R; - - /** - * Use `.toSatisfyAny` when you want to use a custom matcher by supplying a predicate function that returns `true` for any matching value in an array. - * @param {Function} predicate - */ - toSatisfyAny(predicate: (x: any) => boolean): R; - - /** - * Use `.toBeBoolean` when checking if a value is a `Boolean`. - */ - toBeBoolean(): R; - - /** - * Use `.toBeTrue` when checking a value is equal (===) to `true`. - */ - toBeTrue(): R; - - /** - * Use `.toBeFalse` when checking a value is equal (===) to `false`. - */ - toBeFalse(): R; - - /** - * Use `.toBeDate` when checking if a value is a `Date`. - */ - toBeDate(): R; - - /** - * Use `.toBeValidDate` when checking if a value is a `valid Date`. - */ - toBeValidDate(): R; - - /** - * Use `.toBeFunction` when checking if a value is a `Function`. - */ - toBeFunction(): R; - - /** - * Use `.toBeDateString` when checking if a value is a valid date string. - */ - toBeDateString(): R; - - /** - * Use `.toBeHexadecimal` when checking if a value is a valid HTML hex color. - */ - toBeHexadecimal(): R; - - /** - * Use `.toHaveBeenCalledBefore` when checking if a `Mock` was called before another `Mock`. - * - * Note: Required Jest version >=23 - * - * @param {Mock} mock - * @param {boolean} [failIfNoSecondInvocation=true] - */ - toHaveBeenCalledBefore(mock: jest.MockInstance, failIfNoSecondInvocation?: boolean): R; - - /** - * Use `.toHaveBeenCalledAfter` when checking if a `Mock` was called after another `Mock`. - * - * Note: Required Jest version >=23 - * - * @param {Mock} mock - * @param {boolean} [failIfNoFirstInvocation=true] - */ - toHaveBeenCalledAfter(mock: jest.MockInstance, failIfNoFirstInvocation?: boolean): R; - - /** - * Use `.toHaveBeenCalledOnce` to check if a `Mock` was called exactly one time. - */ - toHaveBeenCalledOnce(): R; - - /** - * Use `.toHaveBeenCalledExactlyOnceWith` to check if a `Mock` was called exactly one time with the expected value. - */ - toHaveBeenCalledExactlyOnceWith(...args: unknown[]): R; - - /** - * Use `.toBeNumber` when checking if a value is a `Number`. - */ - toBeNumber(): R; - - /** - * Use `.toBeNaN` when checking a value is `NaN`. - */ - toBeNaN(): R; - - /** - * Use `.toBeFinite` when checking if a value is a `Number`, not `NaN` or `Infinity`. - */ - toBeFinite(): R; - - /** - * Use `.toBePositive` when checking if a value is a positive `Number`. - */ - toBePositive(): R; - - /** - * Use `.toBeNegative` when checking if a value is a negative `Number`. - */ - toBeNegative(): R; - - /** - * Use `.toBeEven` when checking if a value is an even `Number`. - */ - toBeEven(): R; - - /** - * Use `.toBeOdd` when checking if a value is an odd `Number`. - */ - toBeOdd(): R; - - /** - * Use `.toBeWithin` when checking if a number is in between the given bounds of: start (inclusive) and end (exclusive). - * - * @param {Number} start - * @param {Number} end - */ - toBeWithin(start: number, end: number): R; - - /** - * Use `.toBeInRange` when checking if an array has elements in range min (inclusive) and max (exclusive). - * - * @param min - * @param max - */ - toBeInRange(min: number, max: number): R; - - /** - * Use `.toBeObject` when checking if a value is an `Object`. - */ - toBeObject(): R; - - /** - * Use `.toChange` when checking if a value has changed. - * @param {Function} checker - */ - toChange(checker: () => E): R; - - /** - * Use `.toChangeBy` when checking if a value changed by an amount. - * @param {Function} checker - * @param {Number} by - */ - toChangeBy(checker: () => number, by?: number): R; - - /** - * Use `.toChangeTo` when checking if a value changed to a specific value. - * @param {Function} checker - * @param {*} to - */ - toChangeTo(checker: () => E, to: E): R; - - /** - * Use `.toContainKey` when checking if an object contains the provided key. - * - * @param {String} key - */ - toContainKey(key: string): R; - - /** - * Use `.toContainKeys` when checking if an object has all of the provided keys. - * - * @param {Array.} keys - */ - toContainKeys(keys: readonly (keyof E | string)[]): R; - - /** - * Use `.toContainAllKeys` when checking if an object only contains all of the provided keys. - * - * @param {Array.} keys - */ - toContainAllKeys(keys: readonly (keyof E | string)[]): R; - - /** - * Use `.toContainAnyKeys` when checking if an object contains at least one of the provided keys. - * - * @param {Array.} keys - */ - toContainAnyKeys(keys: readonly (keyof E | string)[]): R; - - /** - * Use `.toContainValue` when checking if an object contains the provided value. - * - * @param {*} value - */ - toContainValue(value: E): R; - - /** - * Use `.toContainValues` when checking if an object contains all of the provided values. - * - * @param {Array.<*>} values - */ - toContainValues(values: readonly E[]): R; - - /** - * Use `.toContainAllValues` when checking if an object only contains all of the provided values. - * - * @param {Array.<*>} values - */ - toContainAllValues(values: readonly E[]): R; - - /** - * Use `.toContainAnyValues` when checking if an object contains at least one of the provided values. - * - * @param {Array.<*>} values - */ - toContainAnyValues(values: readonly E[]): R; - - /** - * Use `.toContainEntry` when checking if an object contains the provided entry. - * - * @param {Array.<[keyof E, E[keyof E]>} entry - */ - toContainEntry(entry: readonly [keyof E, E[keyof E]]): R; - - /** - * Use `.toContainEntries` when checking if an object contains all of the provided entries. - * - * @param {Array.>} entries - */ - toContainEntries(entries: readonly (readonly [keyof E, E[keyof E]])[]): R; - - /** - * Use `.toContainAllEntries` when checking if an object only contains all of the provided entries. - * - * @param {Array.>} entries - */ - toContainAllEntries(entries: readonly (readonly [keyof E, E[keyof E]])[]): R; - - /** - * Use `.toContainAnyEntries` when checking if an object contains at least one of the provided entries. - * - * @param {Array.>} entries - */ - toContainAnyEntries(entries: readonly (readonly [keyof E, E[keyof E]])[]): R; - - /** - * Use `.toBeExtensible` when checking if an object is extensible. - */ - toBeExtensible(): R; - - /** - * Use `.toBeFrozen` when checking if an object is frozen. - */ - toBeFrozen(): R; - - /** - * Use `.toBeSealed` when checking if an object is sealed. - */ - toBeSealed(): R; - - /** - * Use `.toResolve` when checking if a promise resolves. - */ - toResolve(): R; - - /** - * Use `.toReject` when checking if a promise rejects. - */ - toReject(): R; - - /** - * Use `.toBeString` when checking if a value is a `String`. - */ - toBeString(): R; - - /** - * Use `.toEqualCaseInsensitive` when checking if a string is equal (===) to another ignoring the casing of both strings. - * - * @param {String} string - */ - toEqualCaseInsensitive(string: string): R; - - /** - * Use `.toStartWith` when checking if a `String` starts with a given `String` prefix. - * - * @param {String} prefix - */ - toStartWith(prefix: string): R; - - /** - * Use `.toEndWith` when checking if a `String` ends with a given `String` suffix. - * - * @param {String} suffix - */ - toEndWith(suffix: string): R; - - /** - * Use `.toInclude` when checking if a `String` includes the given `String` substring. - * - * @param {String} substring - */ - toInclude(substring: string): R; - - /** - * Use `.toIncludeRepeated` when checking if a `String` includes the given `String` substring the correct number of times. - * - * @param {String} substring - * @param {Number} times - */ - toIncludeRepeated(substring: string, times: number): R; - - /** - * Use `.toIncludeMultiple` when checking if a `String` includes all of the given substrings. - * - * @param {Array.} substring - */ - toIncludeMultiple(substring: readonly string[]): R; - - /** - * Use `.toThrowWithMessage` when checking if a callback function throws an error of a given type with a given error message. - * - * @param {Function} type - * @param {String | RegExp} message - */ - toThrowWithMessage( - type: (new (...args: any[]) => { message: string }) | ((...args: any[]) => { message: string }), - message: string | RegExp, - ): R; - - /** - * Use `.toBeEmptyObject` when checking if a value is an empty `Object`. - */ - toBeEmptyObject(): R; - - /** - * Use `.toBeSymbol` when checking if a value is a `Symbol`. - */ - toBeSymbol(): R; - - /** - * Use `.toBeBetween` when checking if a date occurs between `startDate` and `endDate`. - * @param {Date} startDate - * @param {Date} endDate - */ - toBeBetween(startDate: Date, endDate: Date): R; - - /** - * Use `.toBeBeforeOrEqualTo` when checking if a date equals to or occurs before `date`. - * @param {Date} date - */ - toBeBeforeOrEqualTo(date: Date): R; - - /** - * Use `.toBeAfterOrEqualTo` when checking if a date equals to or occurs after `date`. - * @param {Date} date - */ - toBeAfterOrEqualTo(date: Date): R; - - /** - * Use `.toEqualIgnoringWhitespace` when checking if a `String` is equal (===) to given `String` ignoring white-space. - * - * @param {String} string - */ - toEqualIgnoringWhitespace(string: string): R; -} - -declare namespace jest { - // noinspection JSUnusedGlobalSymbols - interface Matchers { - /** - * Note: Currently unimplemented - * Passing assertion - * - * @param {String} message - */ - pass(message: string): R; - - /** - * Note: Currently unimplemented - * Failing assertion - * - * @param {String} message - */ - fail(message: string): never; - - /** - * Use .toBeEmpty when checking if a String '', Array [], Object {} or Iterable (i.e. Map, Set) is empty. - */ - toBeEmpty(): R; - - /** - * Use .toBeOneOf when checking if a value is a member of a given Array. - * @param {Array.<*>} members - */ - toBeOneOf(members: readonly E[]): R; - - /** - * Use `.toBeNil` when checking a value is `null` or `undefined`. - */ - toBeNil(): R; - - /** - * Use `.toSatisfy` when you want to use a custom matcher by supplying a predicate function that returns a `Boolean`. - * @param {Function} predicate - */ - toSatisfy(predicate: (x: E) => boolean): R; - - /** - * Use `.toBeArray` when checking if a value is an `Array`. - */ - toBeArray(): R; - - /** - * Use `.toBeArrayOfSize` when checking if a value is an `Array` of size x. - * @param {Number} x - */ - toBeArrayOfSize(x: number): R; - - /** - * Use `.toBeAfter` when checking if a date occurs after `date`. - * @param {Date} date - */ - toBeAfter(date: Date): R; - - /** - * Use `.toBeBefore` when checking if a date occurs before `date`. - * @param {Date} date - */ - toBeBefore(date: Date): R; - - /** - * Use `.toIncludeAllMembers` when checking if an `Array` contains all the same members of a given set. - * @param {Array.<*>} members - */ - toIncludeAllMembers(members: readonly E[] | E): R; - - /** - * Use `.toIncludeAllPartialMembers` when checking if an `Array` contains all the same partial members of a given set. - * @param {Array.<*>} members - */ - toIncludeAllPartialMembers(members: readonly E[] | E): R; - - /** - * Use `.toIncludeSamePartialMembers` when checking if an `Array` contains exactly the same partial members as a given set, in any order - * @param {Array.<*>} members - */ - toIncludeSamePartialMembers(members: readonly E[]): R; - - /** - * Use `.toIncludeAnyMembers` when checking if an `Array` contains any of the members of a given set. - * @param {Array.<*>} members - */ - toIncludeAnyMembers(members: readonly E[] | E): R; - - /** - * Use `.toIncludeSameMembers` when checking if two arrays contain equal values, in any order. - * @param {Array.<*>} members - */ - toIncludeSameMembers(members: readonly E[]): R; - - /** - * Use `.toPartiallyContain` when checking if any array value matches the partial member. - * @param {*} member - */ - toPartiallyContain(member: E): R; - - /** - * Use `.toSatisfyAll` when you want to use a custom matcher by supplying a predicate function that returns a `Boolean` for all values in an array. - * @param {Function} predicate - */ - toSatisfyAll(predicate: (x: E) => boolean): R; - - /** - * Use `.toSatisfyAny` when you want to use a custom matcher by supplying a predicate function that returns `true` for any matching value in an array. - * @param {Function} predicate - */ - toSatisfyAny(predicate: (x: any) => boolean): R; - - /** - * Use `.toBeBoolean` when checking if a value is a `Boolean`. - */ - toBeBoolean(): R; - - /** - * Use `.toBeTrue` when checking a value is equal (===) to `true`. - */ - toBeTrue(): R; - - /** - * Use `.toBeFalse` when checking a value is equal (===) to `false`. - */ - toBeFalse(): R; - - /** - * Use `.toBeDate` when checking if a value is a `Date`. - */ - toBeDate(): R; - - /** - * Use `.toBeValidDate` when checking if a value is a `valid Date`. - */ - toBeValidDate(): R; - - /** - * Use `.toBeFunction` when checking if a value is a `Function`. - */ - toBeFunction(): R; - - /** - * Use `.toBeDateString` when checking if a value is a valid date string. - */ - toBeDateString(): R; - - /** - * Use `.toBeHexadecimal` when checking if a value is a valid HTML hex color. - */ - toBeHexadecimal(): R; - - /** - * Use `.toHaveBeenCalledBefore` when checking if a `Mock` was called before another `Mock`. - * - * Note: Required Jest version >=23 - * - * @param {Mock} mock - * @param {boolean} [failIfNoSecondInvocation=true] - */ - toHaveBeenCalledBefore(mock: jest.MockInstance, failIfNoSecondInvocation?: boolean): R; - - /** - * Use `.toHaveBeenCalledAfter` when checking if a `Mock` was called after another `Mock`. - * - * Note: Required Jest version >=23 - * - * @param {Mock} mock - * @param {boolean} [failIfNoFirstInvocation=true] - */ - toHaveBeenCalledAfter(mock: jest.MockInstance, failIfNoFirstInvocation?: boolean): R; - - /** - * Use `.toHaveBeenCalledOnce` to check if a `Mock` was called exactly one time. - */ - toHaveBeenCalledOnce(): R; - - /** - * Use `.toHaveBeenCalledExactlyOnceWith` to check if a `Mock` was called exactly one time with the expected value. - */ - toHaveBeenCalledExactlyOnceWith(...args: unknown[]): R; - - /** - * Use `.toBeNumber` when checking if a value is a `Number`. - */ - toBeNumber(): R; - - /** - * Use `.toBeNaN` when checking a value is `NaN`. - */ - toBeNaN(): R; - - /** - * Use `.toBeFinite` when checking if a value is a `Number`, not `NaN` or `Infinity`. - */ - toBeFinite(): R; - - /** - * Use `.toBePositive` when checking if a value is a positive `Number`. - */ - toBePositive(): R; - - /** - * Use `.toBeNegative` when checking if a value is a negative `Number`. - */ - toBeNegative(): R; - - /** - * Use `.toBeEven` when checking if a value is an even `Number`. - */ - toBeEven(): R; - - /** - * Use `.toBeOdd` when checking if a value is an odd `Number`. - */ - toBeOdd(): R; - - /** - * Use `.toBeWithin` when checking if a number is in between the given bounds of: start (inclusive) and end (exclusive). - * - * @param {Number} start - * @param {Number} end - */ - toBeWithin(start: number, end: number): R; - - /** - * Use `.toBeInRange` when checking if an array has elements in range min (inclusive) and max (exclusive). - * - * @param min - * @param max - */ - toBeInRange(min: number, max: number): R; - - /** - * Use `.toBeInteger` when checking if a value is an integer. - */ - toBeInteger(): R; - - /** - * Use `.toBeObject` when checking if a value is an `Object`. - */ - toBeObject(): R; - - /** - * Use `.toChange` when checking if a value has changed. - * @param {Function} checker - */ - toChange(checker: () => E): R; - - /** - * Use `.toChangeBy` when checking if a value changed by an amount. - * @param {Function} checker - * @param {Number} by - */ - toChangeBy(checker: () => number, by?: number): R; - - /** - * Use `.toChangeTo` when checking if a value changed to a specific value. - * @param {Function} checker - * @param {*} to - */ - toChangeTo(checker: () => E, to: E): R; - - /** - * Use `.toContainKey` when checking if an object contains the provided key. - * - * @param {String} key - */ - toContainKey(key: keyof E | string): R; - - /** - * Use `.toContainKeys` when checking if an object has all of the provided keys. - * - * @param {Array.} keys - */ - toContainKeys(keys: readonly (keyof E | string)[]): R; - - /** - * Use `.toContainAllKeys` when checking if an object only contains all of the provided keys. - * - * @param {Array.} keys - */ - toContainAllKeys(keys: readonly (keyof E | string)[]): R; - - /** - * Use `.toContainAnyKeys` when checking if an object contains at least one of the provided keys. - * - * @param {Array.} keys - */ - toContainAnyKeys(keys: readonly (keyof E | string)[]): R; - - /** - * Use `.toContainValue` when checking if an object contains the provided value. - * - * @param {*} value - */ - toContainValue(value: E): R; - - /** - * Use `.toContainValues` when checking if an object contains all of the provided values. - * - * @param {Array.<*>} values - */ - toContainValues(values: readonly E[]): R; - - /** - * Use `.toContainAllValues` when checking if an object only contains all of the provided values. - * - * @param {Array.<*>} values - */ - toContainAllValues(values: readonly E[]): R; - - /** - * Use `.toContainAnyValues` when checking if an object contains at least one of the provided values. - * - * @param {Array.<*>} values - */ - toContainAnyValues(values: readonly E[]): R; - - /** - * Use `.toContainEntry` when checking if an object contains the provided entry. - * - * @param {Array.} entry - */ - toContainEntry(entry: readonly [keyof E, E[keyof E]]): R; - - /** - * Use `.toContainEntries` when checking if an object contains all the provided entries. - * - * @param {Array.>} entries - */ - toContainEntries(entries: readonly (readonly [keyof E, E[keyof E]])[]): R; - - /** - * Use `.toContainAllEntries` when checking if an object only contains all the provided entries. - * - * @param {Array.>} entries - */ - toContainAllEntries(entries: readonly (readonly [keyof E, E[keyof E]])[]): R; - - /** - * Use `.toContainAnyEntries` when checking if an object contains at least one of the provided entries. - * - * @param {Array.>} entries - */ - toContainAnyEntries(entries: readonly (readonly [keyof E, E[keyof E]])[]): R; - - /** - * Use `.toBeExtensible` when checking if an object is extensible. - */ - toBeExtensible(): R; - - /** - * Use `.toBeFrozen` when checking if an object is frozen. - */ - toBeFrozen(): R; - - /** - * Use `.toBeSealed` when checking if an object is sealed. - */ - toBeSealed(): R; - - /** - * Use `.toResolve` when checking if a promise resolves. - */ - toResolve(): Promise; - - /** - * Use `.toReject` when checking if a promise rejects. - */ - toReject(): Promise; - - /** - * Use `.toBeString` when checking if a value is a `String`. - */ - toBeString(): R; - - /** - * Use `.toEqualCaseInsensitive` when checking if a string is equal (===) to another ignoring the casing of both strings. - * - * @param {String} string - */ - toEqualCaseInsensitive(string: string): R; - - /** - * Use `.toStartWith` when checking if a `String` starts with a given `String` prefix. - * - * @param {String} prefix - */ - toStartWith(prefix: string): R; - - /** - * Use `.toEndWith` when checking if a `String` ends with a given `String` suffix. - * - * @param {String} suffix - */ - toEndWith(suffix: string): R; - - /** - * Use `.toInclude` when checking if a `String` includes the given `String` substring. - * - * @param {String} substring - */ - toInclude(substring: string): R; - - /** - * Use `.toIncludeRepeated` when checking if a `String` includes the given `String` substring the correct number of times. - * - * @param {String} substring - * @param {Number} times - */ - toIncludeRepeated(substring: string, times: number): R; - - /** - * Use `.toIncludeMultiple` when checking if a `String` includes all of the given substrings. - * - * @param {Array.} substring - */ - toIncludeMultiple(substring: readonly string[]): R; - - /** - * Use `.toThrowWithMessage` when checking if a callback function throws an error of a given type with a given error message. - * - * @param {Function} type - * @param {String | RegExp} message - */ - toThrowWithMessage( - type: (new (...args: any[]) => { message: string }) | ((...args: any[]) => { message: string }), - message: string | RegExp, - ): R; - - /** - * Use `.toBeEmptyObject` when checking if a value is an empty `Object`. - */ - toBeEmptyObject(): R; - - /** - * Use `.toBeSymbol` when checking if a value is a `Symbol`. - */ - toBeSymbol(): R; - - /** - * Use `.toBeBetween` when checking if a date occurs between `startDate` and `endDate`. - * @param {Date} startDate - * @param {Date} endDate - */ - toBeBetween(startDate: Date, endDate: Date): R; - - /** - * Use `.toBeBeforeOrEqualTo` when checking if a date equals to or occurs before `date`. - * @param {Date} date - */ - toBeBeforeOrEqualTo(date: Date): R; - - /** - * Use `.toBeAfterOrEqualTo` when checking if a date equals to or occurs after `date`. - * @param {Date} date - */ - toBeAfterOrEqualTo(date: Date): R; - - /** - * Use `.toEqualIgnoringWhitespace` when checking if a `String` is equal (===) to given `String` ignoring white-space. - * - * @param {String} string - */ - toEqualIgnoringWhitespace(string: string): R; - } - - // noinspection JSUnusedGlobalSymbols - // eslint-disable-next-line @typescript-eslint/no-empty-object-type - interface Expect extends CustomMatchers {} - - // noinspection JSUnusedGlobalSymbols - // eslint-disable-next-line @typescript-eslint/no-empty-object-type - interface InverseAsymmetricMatchers extends Expect {} -} - -declare module 'jest-extended' { - const matchers: CustomMatchers; - export = matchers; -} diff --git a/yarn.lock b/yarn.lock index 10b20c29..926e6e0c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -474,6 +474,13 @@ human-id "^4.1.1" prettier "^2.7.1" +"@cspotcode/source-map-support@^0.8.0": + version "0.8.1" + resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz#00629c35a688e05a88b1cda684fb9d5e73f000a1" + integrity sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw== + dependencies: + "@jridgewell/trace-mapping" "0.3.9" + "@emnapi/core@^1.4.3": version "1.4.3" resolved "https://registry.yarnpkg.com/@emnapi/core/-/core-1.4.3.tgz#9ac52d2d5aea958f67e52c40a065f51de59b77d6" @@ -812,7 +819,7 @@ "@jridgewell/sourcemap-codec" "^1.4.10" "@jridgewell/trace-mapping" "^0.3.24" -"@jridgewell/resolve-uri@^3.1.0": +"@jridgewell/resolve-uri@^3.0.3", "@jridgewell/resolve-uri@^3.1.0": version "3.1.2" resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz#7a0ee601f60f99a20c7c7c5ff0c80388c1189bd6" integrity sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw== @@ -827,6 +834,14 @@ resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz#3188bcb273a414b0d215fd22a58540b989b9409a" integrity sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ== +"@jridgewell/trace-mapping@0.3.9": + version "0.3.9" + resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz#6534fd5933a53ba7cbf3a17615e273a0d1273ff9" + integrity sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ== + dependencies: + "@jridgewell/resolve-uri" "^3.0.3" + "@jridgewell/sourcemap-codec" "^1.4.10" + "@jridgewell/trace-mapping@^0.3.12", "@jridgewell/trace-mapping@^0.3.18", "@jridgewell/trace-mapping@^0.3.24", "@jridgewell/trace-mapping@^0.3.25": version "0.3.25" resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.25.tgz#15f190e98895f3fc23276ee14bc76b675c2e50f0" @@ -916,6 +931,26 @@ dependencies: "@sinonjs/commons" "^3.0.0" +"@tsconfig/node10@^1.0.7": + version "1.0.11" + resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.11.tgz#6ee46400685f130e278128c7b38b7e031ff5b2f2" + integrity sha512-DcRjDCujK/kCk/cUe8Xz8ZSpm8mS3mNNpta+jGCA6USEDfktlNvm1+IuZ9eTcDbNk41BHwpHHeW+N1lKCz4zOw== + +"@tsconfig/node12@^1.0.7": + version "1.0.11" + resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.11.tgz#ee3def1f27d9ed66dac6e46a295cffb0152e058d" + integrity sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag== + +"@tsconfig/node14@^1.0.0": + version "1.0.3" + resolved "https://registry.yarnpkg.com/@tsconfig/node14/-/node14-1.0.3.tgz#e4386316284f00b98435bf40f72f75a09dabf6c1" + integrity sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow== + +"@tsconfig/node16@^1.0.2": + version "1.0.4" + resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.4.tgz#0b92dcc0cc1c81f6f306a381f28e31b1a56536e9" + integrity sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA== + "@tybys/wasm-util@^0.9.0": version "0.9.0" resolved "https://registry.yarnpkg.com/@tybys/wasm-util/-/wasm-util-0.9.0.tgz#3e75eb00604c8d6db470bf18c37b7d984a0e3355" @@ -1207,7 +1242,14 @@ acorn-jsx@^5.3.2: resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.2.tgz#7ed5bb55908b3b2f1bc55c6af1653bada7f07937" integrity sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ== -acorn@^8.14.0: +acorn-walk@^8.1.1: + version "8.3.4" + resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.3.4.tgz#794dd169c3977edf4ba4ea47583587c5866236b7" + integrity sha512-ueEepnujpqee2o5aIYnvHU6C0A42MNdsIDeqy5BydrkuC5R1ZuUFnm27EeFJGoEHJQgn3uleRvmTXaJgfXbt4g== + dependencies: + acorn "^8.11.0" + +acorn@^8.11.0, acorn@^8.14.0, acorn@^8.4.1: version "8.14.1" resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.14.1.tgz#721d5dc10f7d5b5609a891773d47731796935dfb" integrity sha512-OvQ/2pUDKmgfCg++xsTX1wGxfTaszcHVcTctW4UJB4hibJx2HXxxO5UmVgyjMa+ZDsiaf5wWLXYpRWMmBI0QHg== @@ -1281,6 +1323,11 @@ anymatch@^3.0.3, anymatch@~3.1.2: normalize-path "^3.0.0" picomatch "^2.0.4" +arg@^4.1.0: + version "4.1.3" + resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089" + integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA== + argparse@^1.0.7: version "1.0.10" resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911" @@ -1695,6 +1742,11 @@ create-jest@^29.7.0: jest-util "^29.7.0" prompts "^2.0.1" +create-require@^1.1.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333" + integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ== + cross-spawn@^7.0.3, cross-spawn@^7.0.5, cross-spawn@^7.0.6: version "7.0.6" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.6.tgz#8a58fe78f00dcd70c370451759dfbfaf03e8ee9f" @@ -1793,6 +1845,11 @@ diff-sequences@^29.6.3: resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-29.6.3.tgz#4deaf894d11407c51efc8418012f9e70b84ea921" integrity sha512-EjePK1srD3P08o2j4f0ExnylqRs5B9tJjcp9t1krH2qRi8CCdsYfwe9JgSLurFBWwq4uOlipzfk5fHNvwFKr8Q== +diff@^4.0.1: + version "4.0.2" + resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d" + integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A== + dir-glob@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-3.0.1.tgz#56dbf73d992a4a93ba1584f4534063fd2e41717f" @@ -3516,7 +3573,7 @@ make-dir@^4.0.0: dependencies: semver "^7.5.3" -make-error@^1.3.6: +make-error@^1.1.1, make-error@^1.3.6: version "1.3.6" resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2" integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw== @@ -4490,6 +4547,25 @@ ts-jest@^29.0.0: type-fest "^4.41.0" yargs-parser "^21.1.1" +ts-node@^10.9.2: + version "10.9.2" + resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.9.2.tgz#70f021c9e185bccdca820e26dc413805c101c71f" + integrity sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ== + dependencies: + "@cspotcode/source-map-support" "^0.8.0" + "@tsconfig/node10" "^1.0.7" + "@tsconfig/node12" "^1.0.7" + "@tsconfig/node14" "^1.0.0" + "@tsconfig/node16" "^1.0.2" + acorn "^8.4.1" + acorn-walk "^8.1.1" + arg "^4.1.0" + create-require "^1.1.0" + diff "^4.0.1" + make-error "^1.1.1" + v8-compile-cache-lib "^3.0.1" + yn "3.1.1" + tsc-alias@^1.8.0: version "1.8.16" resolved "https://registry.yarnpkg.com/tsc-alias/-/tsc-alias-1.8.16.tgz#dbc74e797071801c7284f1a478259de920f852d4" @@ -4650,6 +4726,11 @@ uri-js@^4.2.2: dependencies: punycode "^2.1.0" +v8-compile-cache-lib@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf" + integrity sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg== + v8-to-istanbul@^9.0.1: version "9.3.0" resolved "https://registry.yarnpkg.com/v8-to-istanbul/-/v8-to-istanbul-9.3.0.tgz#b9572abfa62bd556c16d75fdebc1a411d5ff3175" @@ -4795,6 +4876,11 @@ yargs@^17.3.1: y18n "^5.0.5" yargs-parser "^21.1.1" +yn@3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50" + integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q== + yocto-queue@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"