Skip to content

feat: Add Vitest integration for end users #9

@AliiiBenn

Description

@AliiiBenn

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

  1. Create src/vitest/ directory
  2. Implement custom matchers:
    • toBeType<T>() - Type equality check
    • toExtend<T>() - Type extends check
    • toHaveProperty(key) - Property existence check
    • toBeAny(), toBeNever(), toBeUnknown() - Special type checks
    • toBeNullable(), toBeOptional() - Nullability checks
    • toBeUnion(), toBeTuple(), toBeArray() - Structure checks
  3. Add setup.ts for automatic matcher registration
  4. Update documentation with Vitest examples
  5. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions