typescript Mocha : Module '"mocha "' has no exported member ' describe'. (2305)

标签 typescript mocha.js webstorm

import {describe, it} from 'mocha'
import {expect} from "chai"

describe('Example Mocha Test 1', function () {
    it('Should test foo', function () {
        let foo = 'bar'
        expect(foo, 'because foo is str').to.be.a('string')
    })
})

获取错误:

Module '"mocha"' has no exported member 'describe'. (2305)
Module '"mocha"' has no exported member 'it'. (2305)

这种导入方式昨天有效,所以我将整个项目更改为这种格式,但今天突然决定不起作用。

我想导入 describeit 的原因是当我像这样导入它时,IDE (WebStorm) 开始自动完成。

当我将代码更改为:

import 'mocha'

代码编译和测试再次开始运行。但我没有得到自动完成。

我安装了 "@types/mocha": "2.2.44",

我该怎么办?

最佳答案

@types/mocha/index.d.ts v. 2.2.44 不包括 describe 等的任何命名导出,因此预计会出现编译器错误. import * as mocha from 'mocha'; 有效,但实际上并不是必需的 - 您不需要显式导入 describe 等,因为 mocha 将它们添加到全局命名空间

关于 typescript Mocha : Module '"mocha "' has no exported member ' describe'. (2305),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47302109/

相关文章:

node.js - 如何在 mocha 测试用例中暂停或等待——setTimeout 不起作用

intellij-idea - 如何将自定义库添加到暂存文件

webstorm - JSDoc 仅描述对象值

typescript - Jasmine 监视导入的模块( typescript )

javascript - 最佳实践/唯一的可能性。 "Json to Javascript/Typescript Object by constructor"

Node.js/Express/Mocha/Supertest Rest API - 空请求正文

javascript - npm test 出错,但 mocha test node.js 出错

unit-testing - WebStorm - 如何编辑 Jasmine 代码完成片段

reactjs - 使用异步 redux-thunk 操作进行存储更改 typescript 的功能测试

node.js - 如何在 Node 迁移中使用 Typescript 作为编译器