我正在使用两个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;
}
尽管测试不完整,但测试未能实例化节点对象,并以以下消息退出:
"TypeError:operations.Node不是构造函数"
我已经尝试过使用
var leftLeft = new Node('left.left', null, null);
也就是说,没有使用operations.Node()
方法。
我正在使用严格模式。