generated from nesalia-inc/package-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
Goal
Add native Vitest integration for end users to make type testing easier and more intuitive in Vitest projects.
Current Situation
Users currently have to use the library like this:
import { check, assert, expect } from '@deessejs/type-testing'
check<string>().equals<string>()
assert<{ a: string }>().hasProperty('a')While this works, it's not integrated with their testing framework and feels disconnected from their test suites.
Proposed Solution
Create a /vitest module with custom Vitest matchers that integrate seamlessly with existing Vitest test suites.
Usage Example
import { expect, test } from 'vitest'
import { toHaveType, toBeType } from '@deessejs/type-testing/vitest'
expect.extend({ toHaveType, toBeType })
test('type checks', () => {
expect<string>().toBeType<string>()
expect<{ a: string }>().toHaveProperty('a')
expect<string>().not.toBeType<number>()
})Auto-setup Option
// vitest.config.ts
import { defineConfig } from 'vitest/config'
import { typeTestingMatchers } from '@deessejs/type-testing/vitest'
export default defineConfig({
setupFiles: ['@deessejs/type-testing/vitest/setup'],
test: {
matchers: typeTestingMatchers()
}
})Implementation Plan
- Create
src/vitest/directory - Implement custom matchers:
toBeType<T>()- Type equality checktoExtend<T>()- Type extends checktoHaveProperty(key)- Property existence checktoBeAny(),toBeNever(),toBeUnknown()- Special type checkstoBeNullable(),toBeOptional()- Nullability checkstoBeUnion(),toBeTuple(),toBeArray()- Structure checks
- Add
setup.tsfor automatic matcher registration - Update documentation with Vitest examples
- Add tests for the Vitest integration
Benefits
- Better DX: Seamless integration with existing Vitest test suites
- More intuitive: Familiar
expect()syntax - Type-safe: Full TypeScript support with autocomplete
- Framework-native: Feels like part of Vitest, not an external tool
- Adoption: Lower barrier to entry for Vitest users
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels