Typescript 如何在没有jest的情况下使用jest dom

Typescript 如何在没有jest的情况下使用jest dom,typescript,react-testing-library,jest-dom,Typescript,React Testing Library,Jest Dom,我有一个关于扩展Typescript接口的问题。 以下是我的情况: 我在测试中使用了expect,没有开玩笑(我单独安装了它,它可以正常工作) 现在我想使用jest-dom为dom添加expect匹配器。(它们非常有用,可以让我的测试更容易编写) 我做了以下事情来扩展预期 import expect from 'expect' import * as matchers from '@testing-library/jest-dom/matchers' expect.extend(matcher

我有一个关于扩展Typescript接口的问题。 以下是我的情况:

我在测试中使用了
expect
,没有开玩笑(我单独安装了它,它可以正常工作)

现在我想使用
jest-dom
为dom添加
expect
匹配器。(它们非常有用,可以让我的测试更容易编写)

我做了以下事情来扩展预期

import expect from 'expect'
import * as matchers from '@testing-library/jest-dom/matchers'

expect.extend(matchers)
这可以工作并添加匹配器,但Typescript不知道它们

我安装了
@types/testing library/jest-dom
,但它没有解决这个问题

查看
@types/testing-library\uu jest-dom
我发现它扩展了
jest
的类型,而不是独立的
expect

我尝试添加一个
expect.d.ts
,内容如下:

import 'expect'

declare module 'expect' {
  export interface Matchers<R> {
    toBeInTheDOM(container?: HTMLElement | SVGElement): R
    // ... other methods
  }
}
导入“expect”
声明模块“expect”{
导出接口匹配器{
toBeInTheDOM(容器?:HTMLElement | svgelElement):R
//…其他方法
}
}
但Typescript仍在抱怨


有什么想法吗?

我找到了解决方案,以下是有效的

import 'expect/build/types'

declare module 'expect/build/types' {
  export interface Matchers<R> {
    // matchers methods here
  }
}
导入“预期/生成/类型”
声明模块“预期/生成/类型”{
导出接口匹配器{
//这里是matchers方法
}
}