问题:
如何使Jest类型不自动出现?他们给我制造了一个假阳性,因为我实际上是在用Mocha运行单元测试。
上下文:
我希望使用TSDX,但在浏览器中运行测试。不幸的是,TSDX预先安装了Jest,没有在浏览器中进行测试。因此,这使得Mocha成为单元测试库的正确选择(因为它很受欢迎,并且在浏览器中运行)。
发布于 2020-11-03 20:09:34
在weDoNotUseJest.d.ts中创建一个名为src的文件
该文件的内容应该是:
declare const expect: "If you're seeing this type, that means you forgot to import expect from Chai. We're not using Jest";
declare const describe: "If you're seeing this type, that means you forgot to place `import 'mocha'` above your test. We're not using Jest";
declare const test: "If you're seeing this type, that means you forgot to place `import 'mocha'` above your test. We're not using Jest";现在,当任何开发人员创建一个新的测试时,IDE (即VSCode)将提供一个更清楚的错误消息。例如,给定以下代码:
import { sum } from '.';
import { expect } from 'chai';
describe('blah', () => {
test('works', () => {
expect(sum(1, 1)).eq(2);
});
});..。实际上,您将看到一条错误消息,它将非常有用:
const describe: "If you're seeing this type, that means you forgot to place导入'mocha‘above your test. We're not using Jest" This expression is not callable. Type 'String' has no call signatures.ts(2349)
https://stackoverflow.com/questions/64669892
复制相似问题