用Mocha测试静态方法



我们有一个带有一些静态方法的javascript类

export default class TestUtils {

static test1() {
return 42;
}
}

我试着用mocha写测试,但是我卡住了。我的测试看起来像这样:

const TestUtils = require("path to TestUtils");
describe("TestUtils", function () {
it("test1 returns 42", function () {
expect(TestUtils.test1()).is.equal(42);
});
});

但是通过运行这个,我得到了一个错误:

TypeError: TestUtils.test1 is not a function
你知道我做错了什么吗?

也许这有点明显,但我希望它能帮助别人。解决方案是使用以下import

const {
default: TestUtils,
} = require("path to TestUtils");

最新更新