@baseplate-dev/core-generators
Version:
Core generators for Baseplate
90 lines • 2.85 kB
TypeScript
import type { TsCodeFragment } from '../renderers/typescript/index.js';
/**
* Options for toMatchTsFragment matcher
*/
export interface ToMatchTsFragmentOptions {
/**
* Whether to ignore hoisted fragments in comparison (default: false)
*/
ignoreHoistedFragments?: boolean;
}
/**
* Options for toIncludeImport matcher
*/
export interface ToIncludeImportOptions {
/**
* Whether the import should be type-only
*/
isTypeOnly?: boolean;
}
/**
* Custom Vitest matchers for TypeScript code fragments
*/
export declare const fragmentMatchers: {
/**
* Asserts that a TypeScript fragment matches the expected fragment
* Compares contents, imports (order-independent), and optionally hoisted fragments
*
* @example
* ```typescript
* expect(actualFragment).toMatchTsFragment(expectedFragment);
* expect(actualFragment).toMatchTsFragment(expectedFragment, {
* ignoreHoistedFragments: true
* });
* ```
*/
toMatchTsFragment(this: {
isNot: boolean;
}, received: TsCodeFragment, expected: TsCodeFragment, options?: ToMatchTsFragmentOptions): {
pass: boolean;
message: () => string;
};
/**
* Asserts that a fragment includes a specific import
*
* @example
* ```typescript
* expect(fragment).toIncludeImport('z', 'zod');
* expect(fragment).toIncludeImport('Prisma', '@prisma/client', { isTypeOnly: true });
* ```
*/
toIncludeImport(this: {
isNot: boolean;
}, received: TsCodeFragment, name: string, from: string, options?: ToIncludeImportOptions): {
pass: boolean;
message: () => string;
};
};
/**
* Extends Vitest's expect with custom matchers for TypeScript fragments
* Call this function once in your test setup to enable the matchers
*
* @example
* ```typescript
* // In test setup file or at the top of test file
* import { extendFragmentMatchers } from '@baseplate-dev/core-generators/test-helpers';
*
* extendFragmentMatchers();
* ```
*/
export declare function extendFragmentMatchers(): void;
/**
* TypeScript module augmentation for custom matchers
* This provides type checking and autocomplete for the custom matchers
*/
export interface FragmentMatchers<R = unknown> {
/**
* Asserts that a TypeScript fragment matches the expected fragment
* Compares contents, imports (order-independent), and optionally hoisted fragments
*/
toMatchTsFragment(expected: TsCodeFragment, options?: ToMatchTsFragmentOptions): R;
/**
* Asserts that a fragment includes a specific import
*/
toIncludeImport(name: string, from: string, options?: ToIncludeImportOptions): R;
}
declare module 'vitest' {
interface Matchers<T = any> extends FragmentMatchers<T> {
}
}
//# sourceMappingURL=matchers.d.ts.map