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)
这种导入方式昨天有效,所以我将整个项目更改为这种格式,但今天突然决定不起作用。
我想导入 describe
和 it
的原因是当我像这样导入它时,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/