Skip to content

Incomplete vitest config configuration for rule vitest/expect-expect fails if a tests has only type assertions (expectTypeOf) #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task
BioPhoton opened this issue Jan 30, 2025 · 1 comment

Comments

@BioPhoton
Copy link

User story

As a testing engineer I want to be able to write test cases that only include type tests.

Example test:

import { assertType, expectTypeOf, describe, it } from 'vitest'
import { mount } from './types.s'

describe('', () => {

  it('my types work properly', () => {. // 👈 this is failing because of a violation of `vitest/expect-expect`
    expectTypeOf(mount).toBeFunction()
    expectTypeOf(mount).parameter(0).toMatchTypeOf<{ name: string }>()
  
    // @ts-expect-error name is a string
    assertType(mount({ name: 42 }))
  })
  
})

This violates the vitest/expect-expect rule in the current configuration.

Acceptance criteria

  • A test case containing only expectTypeOf should pass the vitest/expect-expect rule

Minimal reproduction of current behaviour

import { assertType, expectTypeOf, describe, it } from 'vitest'
import { mount } from './types.s'

describe('', () => {

  // eslint-disable-next-line vitest/expect-expect  // 👈 needed to pass lint target
  it('my types work properly', () => {
    expectTypeOf(mount).toBeFunction()
    expectTypeOf(mount).parameter(0).toMatchTypeOf<{ name: string }>()
  
    // @ts-expect-error name is a string
    assertType(mount({ name: 42 })) 
  })
  
})

Desired behaviour showcase

import { assertType, expectTypeOf, describe, it } from 'vitest'
import { mount } from './types.s'

describe('', () => {

  it('my types work properly', () => { // 👈 lint target passed without disabling rules
    expectTypeOf(mount).toBeFunction()
    expectTypeOf(mount).parameter(0).toMatchTypeOf<{ name: string }>()
  
    // @ts-expect-error name is a string
    assertType(mount({ name: 42 }))
  })
  
})

Which configuration is this related to?

vitest

ESLint version

No response

@vmasek
Copy link
Contributor

vmasek commented Mar 26, 2025

could be solved by #37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants