【问题标题】:TypeScript Mocha: Module '"mocha"' has no exported member 'describe'. (2305)TypeScript Mocha:模块“mocha”没有导出成员“describe”。 (2305)
【发布时间】:2017-11-15 07:57:57
【问题描述】:
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",

我该怎么办?

【问题讨论】:

标签: typescript mocha.js webstorm


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-29
    • 2021-12-25
    • 1970-01-01
    • 2017-02-10
    • 2021-04-09
    • 2019-06-04
    • 2021-12-09
    • 2019-10-01
    相关资源
    最近更新 更多