小编Dav*_*vet的帖子

如何用 Chai 期望替换 Jest 期望的类型?

我想使用 Chai 作为断言库,而不是 Jest。我使用打字稿,我想用 Chai 期望的类型替换全局 Jest 期望。

我尝试做类似的事情:

import chai from "chai";

type ChaiExpect = typeof chai.expect;

declare global {
  export const expect: ChaiExpect;
}

global.expect = chai.expect;
Run Code Online (Sandbox Code Playgroud)

但打字稿抱怨是因为:

Cannot redeclare block-scoped variable 'expect'.ts(2451)
index.d.ts(39, 15): 'expect' was also declared here.
Run Code Online (Sandbox Code Playgroud)

如何覆盖 jest 内部index.d.ts声明的类型?

chai typescript jestjs

2
推荐指数
1
解决办法
2580
查看次数

标签 统计

chai ×1

jestjs ×1

typescript ×1