Javascript Mocha test TypeError: x is not a constructor

Javascript Mocha test TypeError: x is not a constructor

我正在使用两个 js 文件对 Mocha 进行测试。

我的 test.js 文件如下所示:

const assert = require('assert');
const operations = require('./operations.js');

it('Calculates correct deserialization', () => {

  var leftLeft = new operations.Node('left.left', null, null);
  var left = new operations.Node('left', leftLeft, null);
  var right = new operations.Node('right', null, null);
  var root = new operations.Node('root', left, right);
  assert.equal(operations.deserialize(serialize(root)).left.left.val == 'left.left');
});

我的 operations.js 文件如下所示:

function Node(val, left, right) {
  this.val = val;
  this.left = left;
  this.right = right;
}

虽然不完整,但测试未能实例化 Node 对象,并且 退出并显示消息

"TypeError: operations.Node is not a constructor"

我已经尝试过

var leftLeft = new Node('left.left', null, null);

即无德operations.Node()。 我正在使用严格模式。

如果要require()文件作为模块,则必须导出函数:

function Node(val, left, right) {
  this.val = val;
  this.left = left;
  this.right = right;
}

module.exports = Node;