首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我如何隐藏Jest类型,以便我可以使用Mocha?

我如何隐藏Jest类型,以便我可以使用Mocha?
EN

Stack Overflow用户
提问于 2020-11-03 20:09:34
回答 1查看 146关注 0票数 1

问题:

如何使Jest类型不自动出现?他们给我制造了一个假阳性,因为我实际上是在用Mocha运行单元测试。

上下文:

我希望使用TSDX,但在浏览器中运行测试。不幸的是,TSDX预先安装了Jest,没有在浏览器中进行测试。因此,这使得Mocha成为单元测试库的正确选择(因为它很受欢迎,并且在浏览器中运行)。

EN

回答 1

Stack Overflow用户

发布于 2020-11-03 20:09:34

weDoNotUseJest.d.ts中创建一个名为src的文件

该文件的内容应该是:

代码语言:javascript
复制
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)将提供一个更清楚的错误消息。例如,给定以下代码:

代码语言:javascript
复制
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)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64669892

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档