Skip to content

Problem with @testing-library/jest-dom types after updating to v0.30.0 #3156

@azat-io

Description

@azat-io

Describe the bug

vitest.config.ts:

export default mergeConfig(
  viteConfig,
  defineConfig({
    test: {
      setupFiles: './scripts/setup-tests.ts',
    },
    // ....
  }),
)

./scripts/setup-tests.ts:

import matchers from '@testing-library/jest-dom/matchers'
import { expect } from 'vitest'

expect.extend(matchers)

tsconfig.json:

{
  "compilerOptions": {
    "types": ["node", "@testing-library/jest-dom"],
  // ...
  }
}

I am getting typescript errors:

components/button/index.test.tsx:67:38 - error TS2339: Property 'toHaveClass' does not exist on type 'Assertion<HTMLElement>'.

67   expect(getByText(trimmedText)).not.toHaveClass('full')
                                        ~~~~~~~~~~~

components/button/index.test.tsx:68:31 - error TS2339: Property 'toHaveClass' does not exist on type 'Assertion<HTMLElement>'.

68   expect(getByText(fullText)).toHaveClass('full')
                                 ~~~~~~~~~~~

components/button/index.test.tsx:105:36 - error TS2339: Property 'toBeInTheDocument' does not exist on type 'Assertion<HTMLElement>'.

105   expect(screen.getByRole('link')).toBeInTheDocument()

System Info

System:
    OS: macOS 13.3
    CPU: (10) arm64 Apple M1 Pro
    Memory: 413.16 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.15.0 - ~/.asdf/installs/nodejs/18.15.0/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 9.5.0 - ~/.asdf/plugins/nodejs/shims/npm
  Browsers:
    Chrome: 112.0.5615.49
    Firefox: 111.0.1
    Safari: 16.4
  npmPackages:
    @vitejs/plugin-react: ^3.1.0 => 3.1.0
    @vitest/coverage-c8: ^0.30.0 => 0.30.0
    vite: ^4.2.1 => 4.2.1
    vitest: ^0.30.0 => 0.30.0

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

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