Skip to content

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

Open
@BioPhoton

Description

@BioPhoton

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

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