如何在 Mocha it 测试中定义通用函数?

How do I define a common function within a Mocha it test?

我正在编写 Mocha 测试,我正在尝试通过使用不同的参数调用来测试功能。

如何定义可调用的公共函数? 以下 2 个定义都给出了错误:“ReferenceError: commonfunction is not defined”

commonfunction: () => {
};

describe("Blah blah", async (accounts) => {
  it("should do something"), () => {
    commonfunction();
  });
});

describe("Blah blah", async (accounts) => {
  commonfunction: () => {
  };

  it("should do something"), () => {
    commonfunction();
  });
});

您没有声明函数。这些是创建函数的有效语法:

function commonFunction () {
// do things
}

const commonFunction = () => {
// do things
}}

// immediately return true
const commonFunction = () => true

let commonFunction = () = {
// do things
}

// immediately return true
let commonFunction = () => true

这不是:

commonFunction: () => {
}